Ansible : Playbook का उपयोग करें (include)2023/09/27 |
|
अन्य Playbooks से कार्य या Playbooks शामिल करना संभव है।
|
|
| [1] | यदि आप अन्य कार्यों को शामिल करना चाहते हैं, तो [tasks] अनुभाग में [include: ***] लिखें। |
|
ubuntu@dlp:~$
vi playbook_sample.yml # [tasks] निर्देशिका के अंतर्गत [included.yml] शामिल करें
- hosts: target_servers
become: yes
become_method: sudo
tasks:
- include_tasks: tasks/included.yml
# केवल कार्य परिभाषा निर्धारित करना ठीक है
- name: General packages are installed
apt:
name: "{{ packages }}"
state: present
vars:
packages:
- tar
- wget
- unzip
tags: General_Packages
ansible-playbook playbook_sample.yml --ask-become-pass BECOME password: PLAY [target_servers] ********************************************************** TASK [Gathering Facts] ********************************************************* ok: [10.0.0.52] ok: [10.0.0.51] TASK [General packages are installed] ****************************************** ok: [10.0.0.52] ok: [10.0.0.51] PLAY RECAP ********************************************************************* 10.0.0.51 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 10.0.0.52 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
| [2] | अन्य Playbooks आयात करने के लिए, [import_playbook] का उपयोग करें। [1] के अलावा, एक Playbook शामिल करें जो [httpd] चल रहा हो। |
|
ubuntu@dlp:~$
vi playbook_sample.yml
- hosts: target_servers
become: yes
become_method: sudo
tasks:
- include_tasks: tasks/included.yml
# Playbook शामिल करें
- import_playbook: httpd.yml
ubuntu@dlp:~$
vi httpd.yml
- hosts: target_servers
become: yes
become_method: sudo
tasks:
- name: apache2 is installed
apt:
name: apache2
state: present
- name: apache2 is running and enabled
service:
name: apache2
state: started
enabled: yes
ansible-playbook playbook_sample.yml --ask-become-pass BECOME password: PLAY [target_servers] ********************************************************** TASK [Gathering Facts] ********************************************************* ok: [10.0.0.51] ok: [10.0.0.52] TASK [include_tasks] *********************************************************** included: /home/ubuntu/tasks/included.yml for 10.0.0.51, 10.0.0.52 TASK [General packages are installed] ****************************************** ok: [10.0.0.52] ok: [10.0.0.51] PLAY [target_servers] ********************************************************** TASK [Gathering Facts] ********************************************************* ok: [10.0.0.51] ok: [10.0.0.52] TASK [apache2 is installed] **************************************************** ok: [10.0.0.52] ok: [10.0.0.51] TASK [apache2 is running and enabled] ****************************************** ok: [10.0.0.52] ok: [10.0.0.51] PLAY RECAP ********************************************************************* 10.0.0.51 : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 10.0.0.52 : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
| Sponsored Link |
|
|