Module 5 - Ansible
Module 5 - Ansible
AGENDA
What is Ansible?
Ansible Architecture
Ansible Playbook
Ansible Roles
Easy to learn
Written in Python
Highly scalable
Configuration Management
Configuration Management
Josh
Configuration Management
Josh
YAML
Ansible Playbook
Playbook
Inventories Modules
SSH
&
python
Hosts
Playbook
Master
Playbook
Inventories Modules
• List of hosts
• Where playbooktasks
will be operated
Playbook
Inventories Modules
Playbook
Inventories Modules
SSH
&
python
Hosts
Ansible Playbook
Play2
4 Install nginx in host2
- hosts: host2
name: Play 2
sudo: yes
tasks:
2 Execute a script in host1
- name: Execute script on server
script: test_script.sh
- name: Install nginx
apt: name=nginx state=latest 3 Execute a script in host2
---
- hosts: host1
Start YAML file with
sudo: yes [---]
name: Play 1
tasks:
- name: Execute command ‘Date’
Play 1
command: date
- name: Execute script on server
script: test_script.sh
- hosts: host2
name: Play 2
sudo: yes
tasks:
- name: Execute script on server
script: test_script.sh
- name: Install nginx
apt: name=nginx state=latest
Play 2
---
- hosts: host1
Start YAML file with
sudo: yes [---]
name: Play 1
tasks:
- name: Execute command ‘Date’
Play 1
command: date
- name: Execute script on server
script: test_script.sh
[-] Indicates an item
- hosts: host2 in the list
name: Play 2
sudo: yes
tasks:
- name: Execute script on server
script: test_script.sh
- name: Install nginx
apt: name=nginx state=latest
Play 2
command: date
- name: Execute script on server
script: test_script.sh
- hosts: host2
name: Play 2
sudo: yes
tasks:
- name: Execute script on server
script: test_script.sh
- name: Install nginx
apt: name=nginx state=latest
Play 2
---
“hosts” can have one
- hosts: host1 host or group of hosts
sudo: yes from the inventory file
name: Play 1
tasks:
- name: Execute command ‘Date’
Play 1
command: date
- name: Execute script on server Each play is like a dictionary
script: test_script.sh
and has
- hosts: host2 name, hosts, tasks.
name: Play 2 Order doesn’t matter
sudo: yes
tasks:
- name: Execute script on server
script: test_script.sh
- name: Install nginx
apt: name=nginx state=latest
Play 2
---
“hosts” can have one
- hosts: host1 host or group of hosts
sudo: yes from the inventory file
name: Play 1
tasks:
- name: Execute command ‘Date’
Play 1
command: date
- name: Execute script on server Each play is like a dictionary
script: test_script.sh
and has
- hosts: host2 name, hosts, tasks.
name: Play 2 Order doesn’t matter
sudo: yes
tasks:
- name: Execute script on server
script: test_script.sh
- name: Install nginx
apt: name=nginx state=latest So the playbook is a list
of dictionaries
Play 2
---
Similarly tasks are nothing
- hosts: host1
but lists
sudo: yes
name: Play 1 Denoted by [-]
tasks:
- name: Execute command ‘Date’
Play 1
command: date
- name: Execute script on server
script: test_script.sh For tasks ordered
collection.
- hosts: host2
name: Play 2 Position of entry matters
sudo: yes
tasks:
- name: Execute script on server
script: test_script.sh
- name: Install nginx
apt: name=nginx state=latest First entry gets performed
first
Play 2
Defaults: Store data about the role, also store default variables.