RedHat Red Hat Certified Specialist in Developing Automation with Ansible Automation Platform - EX374 Exam Practice Test
Loop through a YAML dictionary to display keys and their values.
Correct Answer:
- name: Display dictionary items hosts: localhost
vars:
services: nginx: enabled mysql: disabled
tasks:
- name: Display each service status debug:
msg: "Service {{ item.key }} is {{ item.value }}" with_dict: "{{ services }}"
Explanation:
with_dict simplifies iterating over key-value pairs in YAML dictionaries, making it ideal for processing complex configurations.
vars:
services: nginx: enabled mysql: disabled
tasks:
- name: Display each service status debug:
msg: "Service {{ item.key }} is {{ item.value }}" with_dict: "{{ services }}"
Explanation:
with_dict simplifies iterating over key-value pairs in YAML dictionaries, making it ideal for processing complex configurations.
Set up multiple files for web1 in host_vars, splitting variables into web1_network.yml and web1_access.yml.
Correct Answer:
echo "ansible_host: 192.168.1.10" > host_vars/web1_network.yml
echo "ansible_user: admin" > host_vars/web1_access.yml
Explanation:
Dividing host variables into multiple files improves modularity, making complex configurations easier to manage.
echo "ansible_user: admin" > host_vars/web1_access.yml
Explanation:
Dividing host variables into multiple files improves modularity, making complex configurations easier to manage.
Automate the update process for EEs in Automation Controller.
Correct Answer:
1. Use the awx-manage command:
awx-manage update_execution_environments --url registry.example.com/my_execution_env --username user --password pass
2. Schedule this command as a cron job.
Explanation:
Automating EE updates ensures they remain current without manual intervention, reducing maintenance overhead.
awx-manage update_execution_environments --url registry.example.com/my_execution_env --username user --password pass
2. Schedule this command as a cron job.
Explanation:
Automating EE updates ensures they remain current without manual intervention, reducing maintenance overhead.
Configure a private registry in Automation Controller to fetch EEs.
Correct Answer:
1. Navigate to Settings > Registries in the Automation Controller.
2. Add a new registry:
o Name: Private Registry
o URL: registry.example.com
o Authentication: Provide credentials.
3. Save the configuration and test connectivity.
Explanation:
Adding a private registry allows Automation Controller to securely fetch and use custom EEs.
2. Add a new registry:
o Name: Private Registry
o URL: registry.example.com
o Authentication: Provide credentials.
3. Save the configuration and test connectivity.
Explanation:
Adding a private registry allows Automation Controller to securely fetch and use custom EEs.
Create a playbook to find all IP addresses in a text file.
Correct Answer:
- name: Extract IP addresses hosts: localhost
tasks:
- name: Read file and extract IPs set_fact:
ip_list: "{{ lookup('file', '/tmp/ips.txt') | regex_findall('\b(?:\d{1,3}\.){3}\d{1,3}\b') }}"
- debug:
var: ip_list
Explanation:
Using regex_findall, this playbook extracts all IP addresses from a file, enabling network data parsing.
tasks:
- name: Read file and extract IPs set_fact:
ip_list: "{{ lookup('file', '/tmp/ips.txt') | regex_findall('\b(?:\d{1,3}\.){3}\d{1,3}\b') }}"
- debug:
var: ip_list
Explanation:
Using regex_findall, this playbook extracts all IP addresses from a file, enabling network data parsing.
Validate the use of a specific EE in a job execution.
Correct Answer:
1. Launch a job template using the EE.
2. Check the job output logs for the EE image used:
o Look for: Using Execution Environment: registry.example.com/my_execution_env:latest.
Explanation:
Validating the EE ensures that the job uses the correct runtime with the required dependencies.
2. Check the job output logs for the EE image used:
o Look for: Using Execution Environment: registry.example.com/my_execution_env:latest.
Explanation:
Validating the EE ensures that the job uses the correct runtime with the required dependencies.
Write a Dockerfile for building the EE.
Correct Answer:
# context/Dockerfile
FROM quay.io/ansible/ansible-runner:latest
COPY requirements.yml /tmp/requirements.yml
RUN ansible-galaxy collection install -r /tmp/requirements.yml
RUN pip install -r /tmp/requirements.yml
Explanation:
The Dockerfile defines the EE's base image and installs the required collections and Python packages.
FROM quay.io/ansible/ansible-runner:latest
COPY requirements.yml /tmp/requirements.yml
RUN ansible-galaxy collection install -r /tmp/requirements.yml
RUN pip install -r /tmp/requirements.yml
Explanation:
The Dockerfile defines the EE's base image and installs the required collections and Python packages.
Create an inventory in Automation Controller using a dynamic inventory script.
Correct Answer:
1. Go to Inventories and add: o Name: Dynamic Inventory
o Source: Custom Script
o Script: Upload the inventory script (e.g., idm_inventory.py).
2. Sync the inventory.
Explanation:
Dynamic inventory scripts allow fetching host information from external systems like databases or cloud platforms.
o Source: Custom Script
o Script: Upload the inventory script (e.g., idm_inventory.py).
2. Sync the inventory.
Explanation:
Dynamic inventory scripts allow fetching host information from external systems like databases or cloud platforms.
Write a playbook to check if a string is alphanumeric.
Correct Answer:
- name: Validate alphanumeric string hosts: localhost
vars:
input_string: "Ansible123" tasks:
- name: Check if string is alphanumeric fail:
msg: "String is not alphanumeric" when: not input_string | isalnum
Explanation:
The isalnum filter validates that a string contains only letters and numbers, ensuring input consistency.
vars:
input_string: "Ansible123" tasks:
- name: Check if string is alphanumeric fail:
msg: "String is not alphanumeric" when: not input_string | isalnum
Explanation:
The isalnum filter validates that a string contains only letters and numbers, ensuring input consistency.
Retrieve data from a YAML file using lookup.
Correct Answer:
# data.yml app: myapp
version: 1.0
- name: Load YAML data hosts: localhost
tasks:
- name: Fetch data set_fact:
app_data: "{{ lookup('file', 'data.yml') | from_yaml }}"
- debug:
var: app_data
Explanation:
The from_yaml filter converts YAML content into a usable dictionary, integrating external configurations into playbooks.
version: 1.0
- name: Load YAML data hosts: localhost
tasks:
- name: Fetch data set_fact:
app_data: "{{ lookup('file', 'data.yml') | from_yaml }}"
- debug:
var: app_data
Explanation:
The from_yaml filter converts YAML content into a usable dictionary, integrating external configurations into playbooks.