Purpose of this playbook is to demonstrate how include tasks defined in a different file.
And how to define variables within the playbook
"include" is the key word to include tasks file
"vars" is the key word to defined variables in the playbook.
YML file to define tasks for playbook.
# copy from here:
# Only the tasks are defined in this file.
- name: Install Web package
yum:
name:
- "{{ web_package }}"
- "{{ db_package }}"
state: latest
- name: Start both DB and Web service
service:
name: "{{ item }}"
state: started
enabled: yes
with_items:
- "{{ web_service }}"
- "{{ db_service }}"
Playbook to import above task file.
# hosts and tasks are the key words in playbook:
# copy from here:
---
- name: Install Web and DB package and start services using variables
hosts: node11
vars: # define list of packages
- web_package: httpd
- web_service: httpd
- db_package: mariadb-server
- db_service: mariadb
tasks:
- name: Install requrie packages
include: envirenment.yml # Import tasks from above yml file.
register: output
- name: Display the output
debug:
var: output
...
No comments:
Post a Comment