pip install ansible
[webservers]
web01.domain.com
web02.domain.com
web03.domain.com
[database]
db01.domain.com
db02.domain.com
[production]
web01.domain.com
web02.domain.com
db01.domain.com
[staging]
web03.domain.com
db02.domain.com
$ ansible web01.domain.com -m ping
web01.domain.com | success >> {
"changed": false,
"ping": "pong"
}
$ ansible web01.domain.com -m setup
web01.domain.com | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"172.31.13.7"
],
...
"ansible_virtualization_role": "guest",
"ansible_virtualization_type": "xen"
},
"changed": false
}
ansible-playbook example.yml
- hosts: webservers
user: root
vars:
domain: www.example.com
tasks:
- name: Install latest nginx
apt: name=nginx state=latest
- name: Configure nginx
template: src=nginx/default.j2 dest=/etc/nginx/sites-available/default
notify: restart nginx
tasks:
- name: Configure nginx
template: name=default.j2 dest=
handlers:
- name: restart nginx
service: name=nginx state=restarted
tasks:
- name: Install required packages
apt: {{ item }}
with_items:
- nginx
- mysql-server
when: ansible_os_family == 'Debian'
Ansible Galaxy