Categories
Uncategorized

Ansible

Ansible

Inventory files:

using groups:

[mail]

mailsvr1.example.com
mailsvr2.example.com

[db]

dbsvr1.example.com
dbsvr2.example.com

[web]

websvr1.example.com
websvr2.example.com

Group servers

[allsvrs:children]

mail
db
web

using alias: using parameters

web    ansible_host=server1.example.com
db ansible_host=server2.example.com

#other parameters, ansible_connection, ansible_port, ansible_user, ansible_ssh_pass

#check ansible Vault to use passwd in encryted format

web    ansible_host=server1.example.com    ansible_connection=ssh  ansible_port=(default is 22)    ansible_user=root
db ansible_host=server2.example.com ansible_connection=winrm ansible_user=admin
mail ansible_host=server3.example.com ansible_connection=ssh ansible_ssh_pass=mypasswd
web2 ansible_host=server4.example.com ansible_connection=winrm ansible_password=winpasswrd

#use localhost to indicate using localhost and not remote host

localhost    ansible_connection=localhost

#Create a new directory script/ansible/inventory.txt

user@ansiblecontroller: vim inventory
backupsvr ansible_host=192.168.1.10 ansible_ssh_pass=mypass
desktop ansible_host=192.168.1.11 ansible_ssh_pass=mypass ansible_ssh_user=myuser

Run ansible:

ansible <hosts> -a <command>
ansible all -a "/sbin/reboot"
ansible <hosts> -m <module>
ansible desktop -m ping -e 'ansible_python_interpreter=/usr/bin/python3' -i inventory.txt

Run Ansible-playbook

ansible-playbook <playbook-name>

Ansible Modules

System: 
- User
- Group
- Hostname
- Iptables
- Make
- Mount
- Service
- Systemd

Commands:
- Command
- Script
- Shell
- Raw

Files:
- Arhive
- File
- Find
- Replace

Database:
- Mysql
- Postgresql

Windows:
- Win_copy
- Win_command
- Win_user