RedHat Red Hat Certified Specialist in Developing Automation with Ansible Automation Platform (EX374) Free Practice Test
Question 1
Transform a list of strings to uppercase using a filter and display the result.
Correct Answer:
- name: Convert to uppercase hosts: localhost
vars:
names: ["ansible", "automation"] tasks:
- name: Uppercase transformation debug:
var: "{{ names | map('upper') | list }}"
Explanation:
The map filter applies a transformation function, such as upper, to each element in a list, enabling bulk data modifications.
vars:
names: ["ansible", "automation"] tasks:
- name: Uppercase transformation debug:
var: "{{ names | map('upper') | list }}"
Explanation:
The map filter applies a transformation function, such as upper, to each element in a list, enabling bulk data modifications.
Question 2
Fetch the latest updates from the remote repository without merging them.
Correct Answer:
git fetch origin
Explanation:
Fetching updates the local metadata with remote changes without altering the working directory or branches.
Explanation:
Fetching updates the local metadata with remote changes without altering the working directory or branches.
Question 3
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.
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 4
Assign multiple EEs to a project in Automation Controller.
Correct Answer:
1. Add EEs to Execution Environments.
2. Assign each EE to different job templates under the same project.
Explanation:
Using multiple EEs allows projects to run playbooks in varied runtime environments.
2. Assign each EE to different job templates under the same project.
Explanation:
Using multiple EEs allows projects to run playbooks in varied runtime environments.
Question 5
Create an inventory to manage multiple environments like staging and production.
Correct Answer:
# inventory.yml
staging:
hosts:
web1:
ansible_host: 192.168.1.11 production:
hosts:
web1:
ansible_host: 192.168.1.20
Explanation:
Environment-specific inventories simplify deployments and maintenance across diverse infrastructure setups.
staging:
hosts:
web1:
ansible_host: 192.168.1.11 production:
hosts:
web1:
ansible_host: 192.168.1.20
Explanation:
Environment-specific inventories simplify deployments and maintenance across diverse infrastructure setups.
Question 6
Create a static inventory with groups web and db, each containing two hosts.
Correct Answer:
# inventory.yml
web:
hosts:
web1:
ansible_host: 192.168.1.10 web2:
ansible_host: 192.168.1.11 db:
hosts:
db1:
ansible_host: 192.168.1.20 db2:
ansible_host: 192.168.1.21
Explanation:
A static inventory organizes hosts into groups for targeted playbook execution, enabling efficient host management.
web:
hosts:
web1:
ansible_host: 192.168.1.10 web2:
ansible_host: 192.168.1.11 db:
hosts:
db1:
ansible_host: 192.168.1.20 db2:
ansible_host: 192.168.1.21
Explanation:
A static inventory organizes hosts into groups for targeted playbook execution, enabling efficient host management.
Question 7
Find the longest string in a list using filters.
Correct Answer:
- name: Find longest string hosts: localhost
vars:
strings: ["ansible", "automation", "platform"]
tasks:
- name: Display longest string debug:
var: "{{ strings | max(attribute='length') }}"
Explanation:
The max filter identifies the largest or longest element in a list based on a specified attribute.
vars:
strings: ["ansible", "automation", "platform"]
tasks:
- name: Display longest string debug:
var: "{{ strings | max(attribute='length') }}"
Explanation:
The max filter identifies the largest or longest element in a list based on a specified attribute.
Question 8
Add a role named webserver to your collection.
Correct Answer:
ansible-galaxy init roles/webserver --collection my_namespace.my_collection
Explanation:
The ansible-galaxy init command creates a skeleton role within the specified collection, facilitating the addition of reusable functionality.
Explanation:
The ansible-galaxy init command creates a skeleton role within the specified collection, facilitating the addition of reusable functionality.
Question 9
Validate the configuration of group_vars for web_servers.
Correct Answer:
ansible-inventory -i inventory.yml --graph
Explanation:
ansible-inventory --graph displays the host and group hierarchy, confirming the correct application of variables.
Explanation:
ansible-inventory --graph displays the host and group hierarchy, confirming the correct application of variables.
Question 10
Test if the EE has the required Python packages installed.
Correct Answer:
podman run --rm my_execution_env:1.0 python -m pip list
Explanation:
Checking installed Python packages ensures the EE is ready for modules or plugins requiring additional dependencies.
Explanation:
Checking installed Python packages ensures the EE is ready for modules or plugins requiring additional dependencies.
Question 11
Update an installed collection to the latest version.
Correct Answer:
ansible-galaxy collection install my_namespace.my_collection --force
Explanation:
Using --force ensures the collection is reinstalled, fetching the latest version if available.
Explanation:
Using --force ensures the collection is reinstalled, fetching the latest version if available.
Question 12
Run a task on localhost but save its output in the context of web1.
Correct Answer:
- name: Local execution with remote context hosts: web1
tasks:
- name: Execute locally
command: echo "Local task output"
delegate_to: localhost
register: local_output
- name: Display output debug:
var: local_output
Explanation:
This setup retains control node task output within the delegating host's scope, enabling contextual analysis.
tasks:
- name: Execute locally
command: echo "Local task output"
delegate_to: localhost
register: local_output
- name: Display output debug:
var: local_output
Explanation:
This setup retains control node task output within the delegating host's scope, enabling contextual analysis.
Question 13
Create a directory structure for building an execution environment (EE).
Correct Answer:
mkdir -p my_execution_env/{context,requirements}
Explanation:
Setting up a structured directory is the first step in creating an execution environment. The context directory holds the Dockerfile, and requirements defines dependencies.
Explanation:
Setting up a structured directory is the first step in creating an execution environment. The context directory holds the Dockerfile, and requirements defines dependencies.
Question 14
Use delegate_facts to control where facts are gathered during delegation.
Correct Answer:
- name: Control fact delegation hosts: web1
tasks:
- name: Gather facts on db1 setup:
delegate_to: db1
delegate_facts: true
Explanation:
The delegate_facts option determines if gathered facts are stored for the delegated host (db1) or the current host (web1).
tasks:
- name: Gather facts on db1 setup:
delegate_to: db1
delegate_facts: true
Explanation:
The delegate_facts option determines if gathered facts are stored for the delegated host (db1) or the current host (web1).
Question 15
Override the SSH port for web1 in the host_vars/web1.yml file.
Correct Answer:
echo "ansible_port: 2222" >> host_vars/web1.yml
Explanation:
The ansible_port variable specifies the SSH port for a host. Adding it to host_vars ensures the override is host-specific.
Explanation:
The ansible_port variable specifies the SSH port for a host. Adding it to host_vars ensures the override is host-specific.
Question 16
Package the collection into a .tar.gz file for distribution.
Correct Answer:
ansible-galaxy collection build my_namespace/my_collection
Explanation:
The build command packages the collection, creating a compressed file ready for sharing or publishing.
Explanation:
The build command packages the collection, creating a compressed file ready for sharing or publishing.
Question 17
Validate if a variable my_ip contains a valid IP address using a filter.
Correct Answer:
- name: Validate IP address hosts: localhost
vars:
my_ip: "192.168.1.1" tasks:
- name: Check if IP is valid
fail:
msg: "Invalid IP address"
when: my_ip | ipaddr is not defined
Explanation:
The ipaddr filter checks if a variable contains a valid IP address, ensuring proper network data validation.
vars:
my_ip: "192.168.1.1" tasks:
- name: Check if IP is valid
fail:
msg: "Invalid IP address"
when: my_ip | ipaddr is not defined
Explanation:
The ipaddr filter checks if a variable contains a valid IP address, ensuring proper network data validation.
Question 18
Set up a CI/CD pipeline to build and upload an EE.
Correct Answer:
# .github/workflows/ci.yml name: EE CI/CD
on: [push]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code uses: actions/checkout@v3
- name: Build EE
run: ansible-builder build --tag my_execution_env:1.0
- name: Push to registry
run: podman push my_execution_env:1.0 registry.example.com/my_execution_env:1.0
Explanation:
This CI/CD pipeline automates the process of building and pushing EEs to a container registry.
on: [push]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code uses: actions/checkout@v3
- name: Build EE
run: ansible-builder build --tag my_execution_env:1.0
- name: Push to registry
run: podman push my_execution_env:1.0 registry.example.com/my_execution_env:1.0
Explanation:
This CI/CD pipeline automates the process of building and pushing EEs to a container registry.
Question 19
Modify the playbook to override ansible_port for web1 in the inventory.
Correct Answer:
echo "ansible_port: 2222" >> host_vars/web1.yml
Explanation:
Overriding ansible_port at the host level ensures compatibility with non-standard SSH configurations.
Explanation:
Overriding ansible_port at the host level ensures compatibility with non-standard SSH configurations.
Question 20
Set up notifications for job completions in Automation Controller.
Correct Answer:
1. Navigate to Notifications.
2. Add a new notification:
o Type: Email, Slack, or Webhook.
o Configure details.
3. Link it to a job template.
Explanation:
Notifications provide immediate feedback on job status, improving monitoring and responsiveness.
2. Add a new notification:
o Type: Email, Slack, or Webhook.
o Configure details.
3. Link it to a job template.
Explanation:
Notifications provide immediate feedback on job status, improving monitoring and responsiveness.