RHCE 8/EX294 Exam Practice Question 5 (Creating Ansible Configuration File & Using ad hoc)

What Should I know About The RHCE Exam

RHCE 8 EX294 exam practice question 5

Question


create a directory in lisa’s home directory with the name, ansible-setup. In the ansible-setup directory, create an ansible configuration file. The ansible configuration file will contain the following:

-harry user as the remote user

-inventory directory as the inventory file. (NOTE: The inventory directory already contains an inventory file and should be copied from ~/lisa to ~/lisa/ansible-setup)

-privilege escalation should be enabled as the root user using sudo mechanism, and without password prompt


Using the Ansible ad hoc command, configure the following:

-create a user with the username, john on the managed hosts in group1 host group

-delete a user with the name, mary on all the managed hosts

-copy the word “Ansible managed systems” to /etc/ansible-config on all the managed hosts using the copy module.

This question is based on understanding and using the Ansible ad hoc command in the RHCE 8/EX294 course on this website. If you have gone through this course, solving this wouldn’t be a problem.

RHCE/EX294 Course

Understanding and using the ansible ad hoc command


Answer

1. Create the /ansible-setup directory

[lisa@drdev1 ~]$ mkdir ansible-setup

2. copy the /inventory directory to /ansible-setup directory

[lisa@drdev1 ~]$ cp -r inventory/ ansible-setup/

3. create the Ansible configuration file

NOTE: IF YOU FORGET THE KEYWORDS THAT SHOULD BE IN THE CONFIGURATION FILE, YOU CAN USE THE /etc/ansible/ansible.cfg FILE AS A REFERENCE.

[lisa@drdev1 ~]$ cd ansible-setup/
[lisa@drdev1 ansible-setup]$ vim ansible.cfg
[defaults]
remote_user=harry
inventory=inventory/

[privilege_escalation]
become=true
become_method=sudo
become_user=root
become_ask-pass=false

4. let’s view the inventory file

[lisa@drdev1 ansible-setup]$ ls

ansible.cfg  inventory
[lisa@drdev1 ansible-setup]$ ls -l inventory/

total 4
-rw-rw-r--. 1 lisa lisa 101 Jun 17 15:39 static-ini-inventory
[lisa@drdev1 ansible-setup]$ cat inventory/static-ini-inventory

[group1]
hqdev1.tekneed.com
localhost

[Asia_region]
hqdev1.tekneed.com

[America_region]
localhost

5. If you wish, you can verify that the inventory file is well configured.

[lisa@drdev1 ansible-setup]$ ansible --list-hosts all

  hosts (2):
    hqdev1.tekneed.com
    localhost

6. create a user, john using ad hoc

[lisa@drdev1 ansible-setup]$ ansible group1 -m user -a 'name=john'

hqdev1.tekneed.com | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
.........
RHCE 8 EX294 exam practice question 5

7. Delete the user, mary on all the managed hosts.

[lisa@drdev1 ansible-setup]$ ansible all -m user -a 'name=mary state=absent'

hqdev1.tekneed.com | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "force": false,
    "name": "mary",
........

8. Copy contents to file.

[lisa@drdev1 ansible-setup]$ ansible all -m copy -a 'content="Ansible managed systems\n" dest=/etc/ansible-config'

hqdev1.tekneed.com | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "checksum": "42f44395d2d97c15c6975013d3b85002d4f703a8",
    "dest": "/etc/ansible-config",
    "gid": 0,
    "group": "root
...........

9. verify the configurations.

[lisa@drdev1 ansible-setup]$ ansible group1 -a 'id john'

hqdev1.tekneed.com | CHANGED | rc=0 >>
uid=1018(john) gid=1022(john) groups=1022(john)

localhost | CHANGED | rc=0 >>
uid=3414(john) gid=3416(john) groups=3416(john)
[lisa@drdev1 ansible-setup]$ ansible all -a 'cat /etc/ansible-config'

localhost | CHANGED | rc=0 >>
Ansible managed systems

hqdev1.tekneed.com | CHANGED | rc=0 >>
Ansible managed systems

NOTE: There are options you may also need to specify while using the Ansible ad hoc, for example, -K, -b, – -ask-pass, – -become, etc. It all depends on what the question says and what you want to achieve.

Solution Summary

mkdir ansible-setup

cp -r inventory/ ansible-setup/

vim ansible.cfg

ansible group1 -m user -a ‘name=john’

ansible all -m user -a ‘name=mary state=absent’

ansible all -m copy -a ‘content=”Ansible managed systems\n” dest=/etc/ansible-config’

click on the link below to watch video on RHCE 8 EX294 exam practice question 5

Watch Video On RHCE 8 EX294 Exam Practice Question 5

Watch Video On Ansible Installation In Linux

Your feedback is welcomed. If you love others, you will share with others

3 Comments

Leave a Reply

Your email address will not be published.


*