- (Exam Topic 2)
Create a playbook called balance.yml as follows:
* The playbook contains a play that runs on hosts in balancers host group and uses the balancer role.
--> This role configures a service to loadbalance webserver requests between hosts in the webservers host group.curl
--> When implemented, browsing to hosts in the balancers host group (for example
http://node5.example.com)
should produce the following output:
Welcome to node3.example.com on 192.168.10.z
--> Reloading the browser should return output from the alternate web server: Welcome to node4.example.com on 192.168.10.a
* The playbook contains a play that runs on hosts in webservers host group and uses the phphello role.
--> When implemented, browsing to hosts in the webservers host group with the URL / hello.php should produce the following output:
Hello PHP World from FQDN
--> where FQDN is the fully qualified domain name of the host. For example,
browsing
to http://node3.example.com/hello.php, should produce the following output: Hello PHP World from node3.example.com
*
Similarly, browsing to http://node4.example.com/hello.php, should produce the following output:
Hello PHP World from node4.example.com
Solution:
Solution as:
# pwd
/home/admin/ansible/
# vim balancer.yml
--
- name: Including phphello role hosts: webservers
roles:
- ./roles/phphello
- name: Including balancer role hosts: balancer
roles:
- ./roles/balancer wq!
# ansible-playbook balancer.yml --syntax-check
# ansible-playbook balancer.yml
Does this meet the goal?
Correct Answer:
A
- (Exam Topic 2)
Install the RHEL system roles package and create a playbook called timesync.yml that:
--> Runs over all managed hosts.
--> Uses the timesync role.
--> Configures the role to use the time server 192.168.10.254 ( Hear in redhat lab use "classroom.example.com" )
--> Configures the role to set the iburst parameter as enabled.
Solution:
Solution as:
# pwd home/admin/ansible/
# sudo yum install rhel-system-roles.noarch -y
# cd roles/
# ansible-galaxy list
# cp -r /usr/share/ansible/roles/rhelsystem-roles.timesync .
# vim timesync.yml
--
- name: timesynchronization hosts: all
vars:
timesync_ntp_provider: chrony timesync_ntp_servers:
- hostname: classroom.example.com _ in exam its ip-address iburst: yes
timezone: Asia/Kolkata roles:
- rhel-system-roles.timesync tasks:
- name: set timezone timezone:
name: "{{ timezone }}" wq!
timedatectl list-timezones | grep india
# ansible-playbook timesync.yml --syntax-check
# ansible-playbook timesync.yml
# ansible all -m shell -a 'chronyc sources -v'
# ansible all -m shell -a 'timedatectl'
# ansible all -m shell -a 'systemctl is-enabled chronyd'
Does this meet the goal?
Correct Answer:
A
- (Exam Topic 2)
Create a playbook called packages.yml that:
---------------------------------------------
--> Installs the php and mariadb packages on hosts in the dev, test, and prod host groups.
--> Installs the Development Tools package group on hosts in the dev host group.
--> Updates all packages to the latest version on hosts in the dev host group.
Solution:
Solution as:
# pwd home/admin/ansible/
# vim packages.yml
--
- name: Install the packages hosts: dev,test,prod
vars:
- php_pkg: php
- mariadb_pkg: mariadb tasks:
- name: install the packages yum:
name:
- "{{ php_pkg }}"
- "{{ mariadb_pkg }}"
state: latest
- name: install the devops tool packages hosts: dev
tasks:
- name: install devepment tools yum:
name: "@Development Tools" state: latest
- name: upgrade all the packages yum:
name: "*" state: latest
exclude: kernel*
!wq
# ansible-playbook package.yml –-syntax-check
# ansible-playbook package.yml
Does this meet the goal?
Correct Answer:
A
- (Exam Topic 1)
Create a file called packages.yml in /home/sandy/ansible to install some packages for the following hosts. On dev, prod and webservers install packages httpd, mod_ssl, and mariadb. On dev only install the development tools package. Also, on dev host update all the packages to the latest.
Solution:
Solution as:
** NOTE 1 a more acceptable answer is likely 'present' since it's not asking to install the latest
state: present
** NOTE 2 need to update the development node
- name: update all packages on development node yum:
'*'name:
state: latest
Does this meet the goal?
Correct Answer:
A
- (Exam Topic 1)
Install and configure ansible
User sandy has been created on your control node with the appropriate permissions already, do not change or modify ssh keys. Install the necessary packages to run ansible on the control node. Configure ansible.cfg to be in folder /home/sandy/ansible/ansible.cfg and configure to access remote machines via the sandy user. All roles should be in the path /home/sandy/ansible/roles. The inventory path should be in
/home/sandy/ansible/invenlory.
Configure these nodes to be in an inventory file where node I is a member of group dev. nodc2 is a member of group test, node3 is a member of group proxy, nodc4 and node 5 are members of group prod. Also, prod is a member of group webservers.
Solution:
In/home/sandy/ansible/ansible.cfg
[defaults] inventory=/home/sandy/ansible/inventory roles_path=/home/sandy/ansible/roles remote_user= sandy host_key_checking=false [privilegeescalation]
become=true become_user=root become_method=sudo become_ask_pass=false
In /home/sandy/ansible/inventory
[dev]
node 1 .example.com [test]
[proxy]
node3 .example.com [prod] node4.example.com node5 .example.com [webservers:children] prod
Does this meet the goal?
Correct Answer:
A