Ansible : Use Playbook#52015/04/22 |
It's possible to include tasks or Playbooks from other Playbooks.
|
|
[1] | If you'd like to include other tasks, write "include: ***" in "tasks" section. |
[cent@dlp ~]$
vi playbook_sample.yml # include "included.yml" under the "tasks" directory - hosts: target_servers become: yes become_method: sudo tasks: - include: tasks/included.yml vars: general_packages: vim-enhanced,wget,unzip - name: General packages are installed yum: name="{{ item }}" state=installed with_items: - "{{ general_packages }}" tags: General_Packages ansible-playbook playbook_sample.yml --ask-become-pass SUDO password: PLAY [target_servers] ********************************************************* GATHERING FACTS *************************************************************** ok: [10.0.0.52] ok: [10.0.0.51] TASK: [General packages are installed] **************************************** changed: [10.0.0.52] => (item=vim-enhanced,wget,unzip) changed: [10.0.0.51] => (item=vim-enhanced,wget,unzip) PLAY RECAP ******************************************************************** 10.0.0.51 : ok=2 changed=1 unreachable=0 failed=0 10.0.0.52 : ok=2 changed=1 unreachable=0 failed=0 |
[2] | If you'd like to include other Playbooks, write like following example. |
[cent@dlp ~]$
vi playbook_sample.yml - hosts: target_servers become: yes become_method: sudo tasks: - include: tasks/included.yml vars: general_packages: vim-enhanced,wget,unzip # include another Playbook - include: httpd.yml
[cent@dlp ~]$
vi httpd.yml - hosts: target_servers become: yes become_method: sudo tasks: - name: httpd is installed yum: name=httpd state=installed - name: httpd is running and enabled service: name=httpd state=started enabled=yes ansible-playbook playbook_sample.yml --ask-become-pass SUDO password: PLAY [target_servers] ********************************************************* GATHERING FACTS *************************************************************** ok: [10.0.0.52] ok: [10.0.0.51] TASK: [General packages are installed] **************************************** changed: [10.0.0.51] => (item=vim-enhanced,wget,unzip) changed: [10.0.0.52] => (item=vim-enhanced,wget,unzip) PLAY [target_servers] ********************************************************* GATHERING FACTS *************************************************************** ok: [10.0.0.52] ok: [10.0.0.51] TASK: [httpd is installed] **************************************************** ok: [10.0.0.51] ok: [10.0.0.52] TASK: [httpd is running and enabled] ****************************************** ok: [10.0.0.51] ok: [10.0.0.52] PLAY RECAP ******************************************************************** 10.0.0.51 : ok=5 changed=1 unreachable=0 failed=0 10.0.0.52 : ok=5 changed=1 unreachable=0 failed=0 |
Sponsored Link |
|