Ansible modülleri değerlerine göre kategorize edilir.
Mesela,
- System modülü: user,group,hostname,iptables,lvg,lvol,make,mount,ping,timezone,systemd,service
- Commands: Komut mpdıllerini kullanmak için kullanılır. Command, expect,raw,script,shell
- Files: Acl, Archive, copy, file,find,lineinfile, replace,state,template, unarchive
- Database: mongodb,mssql,mysql,postgresql, proxysql, vertica vb.
- Cloud: amazon,atmic,azure,digitalocean,docker,google,vmware vb. sistemler ile çalışabilir,
- Windows: win_copy,win_command,win_file,win_domain,win_iis_website,win_ping,win_path,win_robocopy,win_user ve dahasi.
ve dahası docs.ansible.com üzerinde örnekler ile paylaşılmakta.
Bazılarını biraz test edelim.
Command modülü, komutları remote node üzerinde çalıştırmak için kullanılır.
https://docs.ansible.com/ansible/2.5/modules/command_module.html#command-module
Host üzerinde command komutu ile date komutu calıstırıldı yanı sıra cat /etc/resolv.conf komutu kullanılarak direk resolv.conf dosyası cat ile görüntülendi.
-
Name: Play 1
Hosts: localhost
tasks:
- name: Execute command 'date'
command: date
- name: Display resolv.conf contents
command: cat /etc/resolv.conf
Örnek yapalım,
web server nodları üzerinde /tmp/install_script.sh scriptini çalıştıralım. script modülünü kullanarak.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/script_module.html
-
name: 'Execute a script on all web server nodes'
hosts: web_nodes
tasks:
-
name: 'Execute a script on all web server nodes'
script: /tmp/install_script.sh
http servisinin tüm web nodlarında çalıştırılması için palybooku güncelleyelim,
-
name: 'Execute a script on all web server nodes'
hosts: web_nodes
tasks:
-
name: 'Execute a script'
script: /tmp/install_script.sh
-
name: 'Start httpd service'
service: 'name=httpd state=started'
resolv.conf içerisine 10.1.250.10 adresini ekleyecek şekilde lineinfile modülünü kullanarak işlemi gerçekleştirelim,
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html
-
name: 'Execute a script on all web server nodes and start httpd service'
hosts: web_nodes
tasks:
-
name: 'Update entry into /etc/resolv.conf'
lineinfile:
path: /etc/resolv.conf
line: 'nameserver 10.1.250.10'
-
name: 'Execute a script'
script: /tmp/install_script.sh
-
name: 'Start httpd service'
service:
name: httpd
state: present
Yeni bir web kullanıcısı oluşturmak için resolv.conf dan sonra yeni bir komut oluşturalım ve kullanıcı oluşturma işlemini aşağıdaki bilgilere göre gerçekleştirelim,
Username: web_user
uid: 1040
group: developers
Bu işlem için user modülü kullanılacak.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html
-
name: 'Execute a script on all web server nodes and start httpd service'
hosts: web_nodes
tasks:
-
name: 'Update entry into /etc/resolv.conf'
lineinfile:
path: /etc/resolv.conf
line: 'nameserver 10.1.250.10'
-
name: 'Create a new user'
user:
name: web_user
uid: 1040
group: developers
-
name: 'Execute a script'
script: /tmp/install_script.sh
-
name: 'Start httpd service'
service:
name: httpd
state: present