Install ansibleapt/yum -y install ansible Creating hosts for inventorytouch hosts (or you can use /etc/ansible/hosts)
Inventory File cat >> /etc/ansible/hosts
[web]
192.168.0.1
192.168.0.2
192.168.0.3
[db]
192.168.0.4
192.168.0.5
192.168.0.6
[all]
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
192.168.0.6
Copy key to every machine ssh-keygen -t rsa ssh-copy-id [email protected]
Basic commands ansible [db] -m ping ansible [web] -m yum -a "name=httpd state=installed" ansible [all] -a "apt -y update"
-m = module
Creating playbook cat >>playbook.yaml
---
- hosts: web
user: root
tasks:
- name: install apache
apt: pkg=apache2 state=latest
- name: start apache2
service: name=apache2 state=started
- name: start apache2 every bootup
service: name=apache2 enabled=yes
Running playbook ansible-playbook playbook.yaml ansible-playbook -i [web] playbook.yaml