This study guide attempts to cover topics for study in the Red Hat EX407 Red Hat Certificate of Expertise in Ansible Automation exam
Got something to add? Make a Pull Request!
This guide does not divulge any information contained in the test, or style of the objectives. Merely publicly available information based on the wording of the objectives.
ansible -i inventory -m shell -a “hostname"
inventory = /etc/ansible/hosts
defined in ini style
[router]
hostname1 ansibe_host=192.168.1.1
[webserver]
hostname2 ansibe_host=192.168.1.2
[database]
hostname3 ansibe_host=192.168.1.3
[appserver]
hostname4 ansible_host=192.168.1.4
returns json
{
"all": {
"hosts": [
"slaves_slave1"
]
},
"_meta": {
"hostvars": {
"slaves_slave1": {
"ansible_host": "192.168.121.74"
}
}
}
}
file, stat, lineinfile etc
file:
path: /etc/config.cnf
state: absent
file: path=”/etc/config.cnf” state=”absent”
File with a collection of roles/plays
/etc/ansible/ansible.cfg
ansible [groupname] [-i inventory-file] [-m module] [-a arguments]
ansible all -i inventory -m shell -a “hostname”
Dynamic inventories return information from outside sources like AWS to gather facts about the inventory
https://www.jeffgeerling.com/blog/creating-custom-dynamic-inventories-ansible
./inventory.py {} ./inventory.py --list {"all": {"hosts": ["slaves_slave2", "slaves_slave3", "slaves_slave4", "slaves_slave1", "slaves_slave5"]}, "_meta": {"hostvars": {"slaves_slave5": {"ansible_host": "192.168.121.32"}, "slaves_slave4": {"ansible_host": "192.168.121.29"}, "slaves_slave1": {"ansible_host": "192.168.121.218"}, "slaves_slave3": {"ansible_host": "192.168.121.34"}, "slaves_slave2": {"ansible_host": "192.168.121.119"}}}} ./inventory.py --host { "all": { "hosts": [ "slaves_slave1" ] }, "_meta": { "hostvars": { "slaves_slave1": { "ansible_host": "192.168.121.218" } } } }
- fail:
msg: "The system may not be provisioned according to the CMDB status."
when: cmdb_status != "to-be-staged"