RedHat Red Hat Certified Specialist in Developing Automation with Ansible Automation Platform - EX374 Exam Practice Test

Question 1
Use the query function to retrieve data from a dictionary and display it in a task.
Correct Answer:
- name: Query data from dictionary hosts: localhost
vars:
servers:
web: 192.168.1.10
db: 192.168.1.20 tasks:
- name: Retrieve web server IP set_fact:
web_ip: "{{ servers | query('dict', 'web') }}"
- debug:
var: web_ip
Explanation:
The query function retrieves values from complex data structures like dictionaries, enabling advanced data manipulation.
Question 2
Update credentials for a dynamic inventory in Automation Controller.
Correct Answer:
1. Navigate to Credentials.
2. Edit the associated credential.
3. Update the fields (e.g., username, password) and save.
Explanation:
Updating credentials ensures uninterrupted access to dynamic inventory sources, such as APIs or databases.
Question 3
Schedule an EE-based job in Automation Controller.
Correct Answer:
1. Open a job template and navigate to Schedules.
2. Click Add and configure:
o Frequency: Daily
o Time: 12:00 PM.
3. Save the schedule.
Explanation:
Scheduling EEs ensures consistent task execution at regular intervals without manual intervention.
Question 4
Create a playbook to compute the sum of a list of numbers.
Correct Answer:
- name: Compute sum of numbers hosts: localhost
vars:
numbers: [1, 2, 3, 4]
tasks:
- name: Calculate sum debug:
var: "{{ numbers | sum }}"
Explanation:
The sum filter aggregates numerical data, providing a quick computation of totals.
Question 5
Verify host-specific credentials by connecting to each host.
Correct Answer:
ansible all -m ping -i inventory_host_creds.yml
Explanation:
Testing credentials confirms that each host's authentication details are correct and functional.
Question 6
Run a playbook in an EE with a custom inventory file.
Correct Answer:
podman run --rm -v $(pwd):/workspace -w /workspace my_execution_env:1.0 ansible-playbook -i custom_inventory.yml site.yml
Explanation:
Using a custom inventory file within the EE ensures that specific hosts are targeted during playbook execution.
Question 7
Check if a string starts with a specific prefix.
Correct Answer:
- name: Validate string prefix hosts: localhost
vars:
text: "ansible_automation" tasks:
- name: Check prefix fail:
msg: "Invalid prefix"
when: not text.startswith("ansible")
Explanation:
The startswith method ensures strings adhere to expected prefixes, enforcing naming conventions.
Question 8
Clone a private repository using the source control credential.
Correct Answer:
ansible-playbook git_clone.yml --vault-password-file vault_pass.txt git_clone.yml:
- name: Clone repository hosts: localhost tasks:
- git:
repo: "https://github.com/private/repo.git"
dest: "~/repo"
version: "main"
key_file: "~/.ssh/id_rsa"
Explanation:
Using git module with secure credentials fetches repositories for automated deployments or configurations.
Question 9
Implement a loop using a dictionary and display each key-value pair.
Correct Answer:
- name: Loop through dictionary hosts: localhost
vars:
services: nginx: running mysql: stopped
tasks:
- name: Display service statuses debug:
msg: "Service {{ item.key }} is {{ item.value }}" with_dict: "{{ services }}"
Explanation:
The with_dict loop iterates over dictionary key-value pairs, allowing operations on each pair individually.
Question 10
Write a playbook to display all registered variables from previous tasks.
Correct Answer:
- name: Display variables hosts: all
tasks:
- name: Run command
command: echo "Hello"
register: command_output
- debug:
var: command_output
Explanation:
The register directive stores task outputs in variables, making them accessible for subsequent tasks.
Question 11
Create a dynamic inventory script that retrieves hosts from an Identity Management (IdM) server.
Correct Answer:
# idm_inventory.py import json
inventory = {
"all": {
"hosts": ["idm-host1", "idm-host2"],
"vars": {"ansible_user": "admin", "ansible_ssh_private_key_file": "~/.ssh/id_rsa"}
}
}
print(json.dumps(inventory))
Explanation:
Dynamic inventory scripts allow retrieving host data dynamically from sources like an IdM server, ensuring real-time updates.
Question 12
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.
Question 13
Configure a task to run as a specific user, admin, using the become_user directive.
Correct Answer:
- name: Execute as admin user hosts: all
tasks:
- name: List files
become: yes
become_user: admin
command: ls /home/admin
Explanation:
The become_user directive specifies which user to act as during a privileged task, useful for user-specific configurations or actions.