- (Exam Topic 2)
Install and configure Ansible on the control-node control.realmX.example.com as follows:
------------------------------------------------------------------------------------------
--> Install the required packages
--> Create a static inventory file called /home/admin/ansible/inventory as follows: node1.realmX.example.com is a member of the dev host group node2.realmX.example.com is a member of the test host group node3.realmX.example.com & node4.realmX.example.com are members of the prod host group
node5.realmX.example.com is a member of the balancers host group. prod group is a member of the webservers host group
--> Create a configuration file called ansible.cfg as follows:
--> The host inventory file /home/admin/ansible/inventory is defined
--> The location of roles used in playbooks is defined as /home/admin/ansible/ roles
Solution:
Solution as:
Through physical host, login to workstation.lab.example.com with user root.
# ssh root@workstation.lab.example.com
# hostname workstation.lab.example.com
# yum install platform-python*
# su - admin
# pwd
/home/admin/
# vim .vimrc
# mkdir -p ansible/roles
# cd ansible
# vim inventory [dev]
servera.lab.example.com [test] serverb.example.com [prod] serverc.example.com serverd.example.com [balancer] serverd.lab.example.com [webservers:children] prod
!wq
# vim ansible.cfg [defaults]
inventory = ./inventory
role_path = ./roles remote_user = admin ask_pass = false [privilege_escalation] become = true become_method = sudo become_user = root become_ask_pass = false
!wq
# ansible all -–list-hosts
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)
Generate a hosts file:
*
Download an initial template file hosts.j2 from http://classroom.example.com/ hosts.j2 to
/home/admin/ansible/ Complete the template so that it can be used to generate a file with a
line for each inventory host in the same format as /etc/hosts: 172.25.250.9 workstation.lab.example.com workstation
* Create a playbook called gen_hosts.yml that uses this template to generate the file
/etc/myhosts on hosts in the dev host group.
* When completed, the file /etc/myhosts on hosts in the dev host group should have a line for
each managed host:
* 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
* 172.25.250.10 serevra.lab.example.com servera
* 172.25.250.11 serevrb.lab.example.com serverb
* 172.25.250.12 serevrc.lab.example.com serverc
* 172.25.250.13 serevrd.lab.example.com serverd
----------------------------------------------------------------
while practising you to create these file hear. But in exam have to download as per questation.
hosts.j2 file consists.
localhost localhost.localdomain localhost4 localhost4.localdomain4
::1
localhost localhost.localdomain localhost6 localhost6.localdomain6
------------------------------------------------------------------
Solution:
Solution as:
# pwd
/home/admin/ansible
#
wget http://classroom.example.com/hosts.j2
# vim hosts.j2
* 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_facts']['default_ipv4']['address'] }} {{ hostvars[host] ['ansible_facts']['fqdn'] }} {{ hostvars[host]['ansible_facts']['hostname'] }}
{% endfor %} wq!
# vim gen_hosts.yml
--
- name: collecting all host information hosts: all
tasks:
- name: template: src: hosts.j2
dest: /etc/myhosts
when: inventory_hostname in groups['dev'] wq
# ansible-playbook gen_hosts.yml -–syntax-check
# ansible-playbook gen_hosts.yml
Does this meet the goal?
Correct Answer:
A
- (Exam Topic 2)
Create and run an Ansible ad-hoc command.
--> As a system administrator, you will need to install software on the managed nodes.
--> Create a shell script called yum-pack.sh that runs an Ansible ad-hoc command to create yum-repository on each of the managed nodes as follows:
--> repository1
----------
* 1. The name of the repository is EX407
* 2. The description is "Ex407 Description"
* 3. The base URL is http://content.example.com/rhel8.0/x86_64/dvd/BaseOS/
* 4. GPG signature checking is enabled
* 5. The GPG key URL is http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEYredhat- release
* 6. The repository is enabled
--> repository2
----------
* 1. The name of the repository is EXX407
* 2. The description is "Exx407 Description"
* 3. The base URL is http://content.example.com/rhel8.0/x86_64/dvd/AppStream/
* 4. GPG signature checking is enabled
* 5. The GPG key URL is http://content.example.com/rhel8.0/x86_64/dvd/ RPM-GPG-KEYredhat- release
* 6. The repository is enabled
Solution:
Solution as:
# pwd
/home/admin/ansible
# vim yum-pack.sh
#!/bin/bash
ansible all -m yum_repository -a 'name=EX407 description="Ex407 Description"
baseurl=http://content.example.com/rhel8.0/x86_64/dvd/BaseOS/
gpgcheck=yes
gpgkey=http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
enabled=yes'
ansible all -m yum_repository -a 'name=EXX407 description="Exx407 Description"
baseurl=http://content.example.com/rhel8.0/x86_64/dvd/AppStream/
gpgcheck=yes
gpgkey=http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
enabled=yes'
!wq
# chmod +x yum-pack.sh
# bash yum-pack.sh
# ansible all -m command -a 'yum repolist all'
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