Install it in the master node
# apt-get install ansible
add a section to /etc/ansible/hosts
[slaves]
d510
d610
Ping them (make sure you have ssh keys setup in authorized_keys)
# ansible -m ping -u root all
d510 | success >> {
"changed": false,
"ping": "pong"
}
d610 | success >> {
"changed": false,
"ping": "pong"
}
A first play file using apt to install some packages in the “slaves”
---
- name : first play
hosts: slaves
user: root
tasks:
# - name: install gcc
# apt: pkg=gcc state=present
# - name: install nginx
# apt: pkg=nginx state=present
- name: install findx
copy: src=/usr/bin/findx dest=/usr/bin/findx owner=root group=root mode=755
- name: install common packages
action: apt pkg={{item}} state=installed
with_items:
- motion
- nginx
Running it…
# ansible-playbook play.yml
PLAY [first play] *************************************************************
GATHERING FACTS ***************************************************************
ok: [d510]
ok: [d610]
TASK: [install findx] *********************************************************
ok: [d610]
ok: [d510]
TASK: [install common packages] ***********************************************
ok: [d610] => (item=motion,nginx)
ok: [d510] => (item=motion,nginx)
PLAY RECAP ********************************************************************
d510 : ok=3 changed=0 unreachable=0 failed=0
d610 : ok=3 changed=0 unreachable=0 failed=0