
Online Questions - Valid Practice To your EX374 Exam (Updated 300 Questions)
Practice To EX374 - Remarkable Practice On your Red Hat Certified Specialist in Developing Automation with Ansible Automation Platform Exam
NEW QUESTION # 109
Create a playbook to override the default inventory SSH port by using a special variable at runtime.
Answer:
Explanation:
# playbook.yml
- name: Test connection with overridden SSH port hosts: web1
tasks:
- ping:
Execution:
ansible-playbook -i inventory.yml playbook.yml -e "ansible_port=2022"
Explanation:
Passing ansible_port as an extra variable ensures runtime overrides without altering the inventory.
NEW QUESTION # 110
Validate if a variable my_ip contains a valid IP address using a filter.
Answer:
Explanation:
- 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.
NEW QUESTION # 111
Write a playbook to use the lookup plugin to retrieve a secret from a file.
Answer:
Explanation:
- name: Retrieve secret hosts: localhost tasks:
- name: Get secret set_fact:
secret: "{{ lookup('file', '/etc/secret.key') }}"
- debug:
var: secret
Explanation:
Using lookup with the file plugin securely retrieves sensitive information from external files.
NEW QUESTION # 112
Create a static inventory with groups web and db, each containing two hosts.
Answer:
Explanation:
# 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.
NEW QUESTION # 113
Schedule an EE-based job in Automation Controller.
Answer:
Explanation:
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.
NEW QUESTION # 114
Update an EE with new dependencies.
Answer:
Explanation:
1. Modify requirements.yml with additional dependencies.
2. Rebuild the EE:
ansible-builder build --tag my_execution_env:1.1
3. Push the updated EE:
podman push my_execution_env:1.1 registry.example.com/my_execution_env:1.1
Explanation:
Updating the EE ensures it includes the latest dependencies required by new playbooks or modules.
NEW QUESTION # 115
Replace a substring in all elements of a list.
Answer:
Explanation:
- name: Replace substrings hosts: localhost
vars:
items: ["file_1.log", "file_2.log", "file_3.log"] tasks:
- name: Transform filenames debug:
var: "{{ items | map('regex_replace', '_', '-') | list }}"
Explanation:
The regex_replace filter applies pattern-based transformations to all elements in a list.
NEW QUESTION # 116
Filter out duplicate items from a list.
Answer:
Explanation:
- name: Remove duplicates hosts: localhost
vars:
items: [1, 2, 2, 3, 3, 4] tasks:
- name: Unique list debug:
var: "{{ items | unique }}"
Explanation:
The unique filter removes duplicate elements, ensuring clean and distinct data.
NEW QUESTION # 117
Verify the directory structure of an existing collection.
Answer:
Explanation:
tree ~/.ansible/collections/ansible_collections/my_namespace/my_collection
Explanation:
The tree command provides a visual representation of the collection structure, ensuring proper organization.
NEW QUESTION # 118
Merge the feature-update branch into the main branch to integrate the changes.
Answer:
Explanation:
git checkout main
git merge feature-update
Explanation:
Switching to the target branch and merging ensures that changes from the source branch are integrated systematically.
NEW QUESTION # 119
Run a playbook with a different Ansible configuration file in an EE.
Answer:
Explanation:
podman run --rm -v $(pwd):/workspace -w /workspace my_execution_env:1.0 ansible-playbook -e ANSIBLE_CONFIG=/workspace/ansible.cfg site.yml
Explanation:
Overriding the Ansible configuration file allows customization of playbook execution parameters within the EE.
NEW QUESTION # 120
Write a playbook to verify if all hosts in the staging group have an accessible HTTP port (http_port).
Answer:
Explanation:
- name: Verify HTTP port hosts: staging
tasks:
- debug:
msg: "Host {{ inventory_hostname }} is using HTTP port {{ http_port }}"
Explanation:
Playbooks accessing group variables verify configurations, such as application ports, across a group.
NEW QUESTION # 121
Validate if a given string ends with a specific suffix.
Answer:
Explanation:
- name: Validate string suffix hosts: localhost
vars:
filename: "document.txt" tasks:
- name: Check suffix fail:
msg: "File does not end with .txt" when: not filename.endswith(".txt")
Explanation:
The endswith method ensures filenames conform to expected extensions or formats.
NEW QUESTION # 122
Use content from Automation Hub in a playbook.
Answer:
Explanation:
- name: Use Automation Hub role hosts: all
roles:
- ansible_role_from_hub
Explanation:
Playbooks can directly use roles from Automation Hub, simplifying the inclusion of pre-built automation tasks.
NEW QUESTION # 123
Test the dynamic inventory script.
Answer:
Explanation:
ansible-inventory -i idm_inventory.py --list
Explanation:
Running the dynamic inventory script with ansible-inventory ensures it generates valid host data.
NEW QUESTION # 124
Create a playbook to run only tasks tagged as install.
Answer:
Explanation:
# playbook.yml
- name: Tagged tasks example hosts: all
tasks:
- name: Install nginx yum:
name: nginx
state: present tags: install
Execution:
ansible-playbook -i inventory.yml playbook.yml --tags "install"
Explanation:
Tags allow selective execution of tasks in a playbook, making debugging and incremental updates more efficient.
NEW QUESTION # 125
Sync dynamic inventory with Automation Controller.
Answer:
Explanation:
1. Go to Inventories in Automation Controller.
2. Add a new inventory and set the source as Custom Script.
3. Upload the dynamic inventory script.
Explanation:
Syncing dynamic inventories with Automation Controller ensures up-to-date host management for jobs.
NEW QUESTION # 126
Test the webserver role from the collection using ansible-playbook.
Answer:
Explanation:
ansible-playbook test_playbook.yml
Explanation:
Running a playbook verifies that the collection roles are functional and properly integrated.
NEW QUESTION # 127
Verify the installed collections on your system.
Answer:
Explanation:
ansible-galaxy collection list
Explanation:
The list command displays all installed collections, confirming the availability of required collections.
NEW QUESTION # 128
Set up a source control credential for Git repositories.
Answer:
Explanation:
ansible-vault create git_creds.yml
Add credentials:
git_user: "git_user"
git_token: "secure_token"
Explanation:
Source control credentials stored securely allow automation tools to fetch playbooks or configurations from repositories.
NEW QUESTION # 129
Configure Automation Controller to use custom inventory scripts.
Answer:
Explanation:
1. Go to Inventories in Automation Controller.
2. Add a new inventory and set the source to Custom Script.
3. Upload the custom script.
Explanation:
Custom inventory scripts provide flexibility to fetch and manage hosts in complex environments.
NEW QUESTION # 130
Set up a schedule to update EEs in Automation Controller.
Answer:
Explanation:
1. Go to Schedules in Automation Controller.
2. Create a schedule for the Execution Environment Sync.
3. Set the frequency to match organizational update policies.
Explanation:
Scheduling updates ensures EEs are always up-to-date with the latest dependencies and fixes.
NEW QUESTION # 131
Use a special variable to set a different remote user for web1 when executing a playbook.
Answer:
Explanation:
# host_vars/web1.yml ansible_user: custom_user
Explanation:
Special variables like ansible_user dynamically override the remote user, adapting Ansible behavior per host.
NEW QUESTION # 132
Combine multiple lists into one list using filters.
Answer:
Explanation:
- name: Combine lists hosts: localhost vars:
list1: [1, 2, 3]
list2: [4, 5, 6] tasks:
- name: Merge lists debug:
var: "{{ list1 + list2 }}"
Explanation:
Combining lists into a single structure is straightforward with Ansible filters, enabling unified data manipulation.
NEW QUESTION # 133
......
True EX374 Exam Extraordinary Practice For the Exam: https://pass4sure.testpdf.com/EX374-practice-test.html
