Ansible playbook.yml by roles

Ansible playbook are just like normal file with ".yml" extension. Playbook (.yml) file understand set of define syntax. YAML is easier for humans to read and write than other common data formats like XML or JSON.


Ansible Flow





















Create the dir/file as mention below:
[vagrant@www.tutorialbyexample.com ansible]$ pwd
/ansible
[vagrant@www.tutorialbyexample.com ansible]$ ls -R
.:
etc  inventory  provision.sh

./etc:
ansible

./etc/ansible:
roles  site.yml  web.yml

./etc/ansible/roles:
zip

./etc/ansible/roles/zip:
tasks

./etc/ansible/roles/zip/tasks:
main.yml

./inventory:

dev


Let's discussed more details for file:

[vagrant@www.tutorialbyexample.com ansible]$ vi inventory/dev (There is no extensions)
local ansible_ssh_port=2222 ansible_ssh_host=127.0.0.1 ansible_connection=local

[web-servers]

local

[vagrant@www.tutorialbyexample.com ansible]$ vi provision.sh
sudo ansible-playbook -vvvv -i /tmp/inventory/$1 /ansible/site.yml --extra-vars

[vagrant@www.tutorialbyexample.com ansible]$ vi etc/ansible/site.yml
---
- include: web.yml

[vagrant@www.tutorialbyexample.com ansible]$ vi etc/ansible/web.yml
---
- hosts: web-servers
  remote_user: root
  sudo: yes
  roles:
    - zip

[vagrant@www.tutorialbyexample.com ansible]$ vi etc/ansible/roles/zip/tasks/main.yml
---
- name: Install zip/unzip util
  yum: name={{ item }} state=present
  with_items:
    - "zip"
    - "unzip"

Run it:
[vagrant@www.tutorialbyexample.com ansible]$ ./provision.sh dev

PLAY [web-servers] *******************************************

GATHERING FACTS          *************************************
<127.0.0.1> REMOTE_MODULE setup

ok: [local]

TASK: [zip | Install zip/unzip util] ******************************************
<127.0.0.1> REMOTE_MODULE yum name=zip,unzip state=present


PLAY RECAP ********************************************************************

local                      : ok=2    changed=0    unreachable=0    failed=0

Great, zip utility installed with help of Ansible play book or .yml file with roles. 


Video on Youtube: https://www.youtube.com/watch?v=r0DDwWExBC4




References

http://www.ansible.com/

2 comments:

  1. how to installed ansible and ansible playbook?

    ReplyDelete
  2. This above information really Good beginners are looking for these type of blogs, Thanks for sharing article on Devops Online Training Hyderabad

    ReplyDelete