Ansible Playbook Vars/Day2/LAB-part2
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
1. Create a playbook and setup a webserver(httpd) and use httpd as a variable decalared in role var file
---
-name: webserver
host:web
vars_files:
- role-var-file.yml
tasks:
-name: var include
include_vars: role-var-file.yml
-name: setup httpd server
yum:
name: "{{packname}}"
state: latest
- name: Start service httpd, if not started
ansible.builtin.service:
name: "{{packname}}"
state: started
2. Create a playbook and setup a webserver(httpd) and use httpd as a variable decalared using prompt
---
-name: webserver
host:web
vars_prompt:
- name: "packname"
prompt: "Install httpd"
private: false
tasks:
-name: var include
include_vars: role-var-file.yml
-name: setup httpd server
yum:
name: "{{packname}}"
state: latest
- name: Start service httpd, if not started
ansible.builtin.service:
name: "{{packname}}"
state: started
- name: Print the vars
ansible.builtin.debug:
msg: service httpd {{packname}} installed and started
3. Create a playbook and setup a webserver(httpd) and find a list of .txt file in some directory and output using register variables
---
-name: webserver
host:web
vars_prompt:
- name: "packname"
prompt: "Install httpd"
private: false
tasks:
-name: var include
include_vars: role-var-file.yml
-name: setup httpd server
yum:
name: "{{packname}}"
state: latest
- name: Start service httpd, if not started
ansible.builtin.service:
name: "{{packname}}"
state: started
- name: Print the vars
ansible.builtin.debug:
msg: service httpd {{packname}} installed
-name:
shell: "find *.txt"
args:
chdir: "/home/centos/ansible/priyanka"
register: find_output
4. Create a playbook and setup a webserver(httpd), copy a index.html and interpolate variables in template file decalared in playbook.
---
-name: webserver
host:web
vars_prompt:
- name: "packname"
prompt: "Install httpd"
private: false
tasks:
-name: var include
include_vars: role-var-file.yml
-name: setup httpd server
yum:
name: "{{packname}}"
state: latest
- name: copy index.html
ansible.builtin.template:
src: index.html.j2
dest: /var/www/html/
- name: Start service httpd, if not started
ansible.builtin.service:
name: "{{packname}}"
state: started