RedHat EX294 Exam - Topic 9 Question 42 Discussion
Create a role called apache in "/home/admin/ansible/roles" with the followingrequirements:--> The httpd package is installed, enabled on boot, and started.--> The firewall is enabled and running with a rule to allow access to the web server.--> template file index.html.j2 is used to create the file /var/www/html/index.htmlwith the output:Welcome to HOSTNAME on IPADDRESS--> Where HOSTNAME is the fqdn of the managed node and IPADDRESS is the IP-Address ofthe managed node.note: you have to create index.html.j2 file.--> Create a playbook called httpd.yml that uses this role and the playbook runs onhosts in the webservers host group.
A) Explanation:
Solution as:
----------
# pwd
/home/admin/ansible/roles/
# ansible-galaxy init apache
# vim apache/vars/main.yml
---
# vars file for apache
http_pkg: httpd
firewall_pkg: firewalld
http_srv: httpd
firewall_srv: firewalld
rule: http
webpage: /var/www/html/index.html
template: index.html.j2
:wq!
# vim apache/tasks/package.yml
---
- name: Installing packages
yum:
name:
- '{{http_pkg}}'
- '{{firewall_pkg}}'
state: latest
:wq!
# vim apache/tasks/service.yml
---
- name: start and enable http service
service:
name: '{{http_srv}}'
enabled: true
state: started
- name: start and enable firewall service
service:
name: '{{firewall_srv}}'
enabled: true
state: started
:wq!
# vim apache/tasks/firewall.yml
---
- name: Adding http service to firewall
firewalld:
service: '{{rule}}'
state: enabled
permanent: true
immediate: true
:wq!
# vim apache/tasks/webpage.yml
---
- name: creating template file
template:
src: '{{template}}'
dest: '{{webpage}}'
notify: restart_httpd
!wq
# vim apache/tasks/main.yml
# tasks file for apache
- import_tasks: package.yml
- import_tasks: service.yml
- import_tasks: firewall.yml
- import_tasks: webpage.yml
:wq!
# vim apache/templates/index.html.j2
Welcome to {{ ansible_facts.fqdn }} on {{ ansible_facts.default_ipv4.address }}
# vim apache/handlers/main.yml
---
# handlers file for apache
- name: restart_httpd
service:
name: httpd
state: restarted
:wq!
# cd ..
# pwd
/home/admin/ansible/
# vim httpd.yml
---
- name: Including apache role
hosts: webservers
pre_tasks:
- name: pretask message
debug:
msg: 'Ensure webserver configuration'
roles:
- ./roles/apache
post_tasks:
- name: Check webserver
uri:
url: 'http://{{ ansible_facts.default_ipv4.address }}'
return_content: yes
status_code: 200
:wq!
# ansible-playbook httpd.yml ---syntax-check
# ansible-playbook httpd.yml
# curl http://serverx
Corazon
9 months agoReta
10 months agoDetra
10 months agoMirta
10 months agoDierdre
10 months agoRemona
11 months agoJudy
11 months agoKarol
11 months agoLeana
11 months agoJerry
11 months agoReyes
11 months agoSabra
11 months agoEun
11 months agoFlorinda
11 months agoRicki
11 months agoIsaac
11 months agoLeslee
11 months agoHuey
2 years agoEvan
2 years agoLaila
2 years agoEvelynn
2 years agoHolley
2 years agoAide
2 years agoSherell
2 years agoGeorgiana
2 years agoArmanda
2 years agoSherell
2 years agoGeorgiana
2 years agoSherell
2 years agoArmanda
2 years agoSherell
2 years agoGeorgiana
2 years agoSherell
2 years ago