Ansible Playbooks
- Ansible Playbook is a declarative way of expressing the tasks to be done on the nodes.
- It is expressed in yaml
- Playbook is collect of play’s
- Each Play will have
- hosts: where to execute
- tasks: Each task is achieved by module
- roles:
- become: this applies to play or task which means do we need sudo
- Structure of Ansible playbook: Create a yaml file
---
- name: <play-1>
hosts: <where to execute>
become: yes|no
tasks:
- name: <task 1>
<module>:
param-1: <value-1>
..
param-n: <value-n>
- name: <play-2>
hosts: <where to execute>
become: yes|no
tasks:
- name: <task 1>
<module>:
param-1: <value-1>
..
param-n: <value-n>
...
- name: <play-n>
hosts: <where to execute>
become: yes|no
tasks:
- name: <task 1>
<module>:
param-1: <value-1>
..
param-n: <value-n>
Lets create a playbook for deploying the website
- installing nginx
- create a playbook called website.yaml and hosts file Refer Here for the changes done
- Now lets look at ansible-playbook
ansible-playbook --help
ansible-playbook --syntax-check -i hosts website.yaml

- Lets execute the dry run: Which approximately tells you what would happen when you execute the playbook without installing/configuring on node.
- note: dry run might not work in all cases
ansible-playbook --check -i hosts website.yaml
- Now lets execute the playbook
ansible-playbook -i hosts website.yaml
-
When we execute ansible playbook we get a status at end of every task
- ok (everything is done already)
- changed (ansible executed to meet what you want)

-
It is not necessary to write a task per step, in some case we can combine Refer Here
-
Refer Here for the changes to download website
-
Exercise: With my current playbook to access website i have to access
http://publicip/templatemo_589_lugx_gaming/, but i want to access on http://publicip
Like this:
Like Loading...