Quality EX374 PDF Dumps - EX374 Exam Questions [Q17-Q39]

Share

Quality EX374 PDF Dumps - EX374 Exam Questions

Most UptoDate RedHat EX374 Exam Dumps PDF 2025

NEW QUESTION # 17
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 # 18
Use ansible_inventory to display host-specific variables.

Answer:

Explanation:
ansible-inventory -i inventory.yml --host web1
Explanation:
This command retrieves detailed information about host variables, verifying correctness and debugging issues.


NEW QUESTION # 19
Perform a health check on db1 from web1.

Answer:

Explanation:
- name: Health check on db1 hosts: web1
tasks:
- name: Ping db1 ping: delegate_to: db1
Explanation:
Using the ping module with delegate_to, this task verifies the availability of db1 from web1.


NEW QUESTION # 20
Package the collection into a .tar.gz file for distribution.

Answer:

Explanation:
ansible-galaxy collection build my_namespace/my_collection
Explanation:
The build command packages the collection, creating a compressed file ready for sharing or publishing.


NEW QUESTION # 21
Control whether delegated facts are stored for the target host or the delegating host.

Answer:

Explanation:
- name: Delegate and control facts hosts: web1
tasks:
- name: Gather facts for db1 setup:
delegate_to: db1
delegate_facts: false
Explanation:
Setting delegate_facts: false stores gathered facts in the context of the delegating host rather than the target.


NEW QUESTION # 22
Modify the playbook to override ansible_port for web1 in the inventory.

Answer:

Explanation:
echo "ansible_port: 2222" >> host_vars/web1.yml
Explanation:
Overriding ansible_port at the host level ensures compatibility with non-standard SSH configurations.


NEW QUESTION # 23
Run a task on a different host than the one defined in the inventory using delegate_to.

Answer:

Explanation:
- name: Delegate task to another host hosts: web1
tasks:
- name: Run a command on db1
command: uptime
delegate_to: db1
Explanation:
The delegate_to keyword ensures the task is executed on db1, even if the play is targeting web1. This is useful for tasks requiring resources or operations on another host.


NEW QUESTION # 24
Create an inventory that uses multiple groups and defines variables for each.

Answer:

Explanation:
# inventory.yml
all:
children:
web_servers: hosts: web1:
db_servers: hosts: db1:
vars:
ansible_user: deploy
Explanation:
Grouping hosts and defining variables globally ensures consistent configuration across multiple groups.


NEW QUESTION # 25
Configure web1 to use sudo for privilege escalation and run a playbook to display the hostname.

Answer:

Explanation:
echo "ansible_become: yes" > host_vars/web1.yml
Playbook:
- name: Check hostname hosts: web1
tasks:
- command: hostname
Explanation:
The ansible_become variable enables privilege escalation for tasks requiring elevated permissions.


NEW QUESTION # 26
Run a command on the control node but store the result in the context of a managed host.

Answer:

Explanation:
- name: Store control node result hosts: web1
tasks:
- name: Get disk usage on control node
command: df -h
delegate_to: localhost
register: disk_usage
- name: Show disk usage debug:
var: disk_usage
Explanation:
This task demonstrates delegating commands to the control node while retaining results within the managed host's context.


NEW QUESTION # 27
Use failed_when to define custom failure conditions for a task.

Answer:

Explanation:
- name: Custom failure hosts: all
tasks:
- name: Fail if output is not 'success'
command: echo "fail"
register: output
failed_when: "'success' not in output.stdout"
Explanation:
The failed_when directive enables fine-grained control over failure conditions, improving playbook robustness.


NEW QUESTION # 28
Set up CI/CD for your collection to test and publish it automatically to Ansible Galaxy.

Answer:

Explanation:
# .github/workflows/ci.yml
name: CI/CD for Ansible Collection
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository uses: actions/checkout@v3
- name: Test collection
run: ansible-test sanity
- name: Build collection
run: ansible-galaxy collection build
- name: Publish to Galaxy
run: ansible-galaxy collection publish my_namespace-my_collection-*.tar.gz --api-key ${{ secrets.GALAXY_API_KEY }}
Explanation:
This GitHub Actions workflow automates testing, building, and publishing your collection to Ansible Galaxy.


NEW QUESTION # 29
Create a custom configuration for the EE in Automation Controller.

Answer:

Explanation:
1. Navigate to Execution Environments in the Automation Controller.
2. Add a new EE entry:
o Name: Custom EE
o Image: registry.example.com/my_execution_env:1.0
3. Associate the EE with a project or job template.
Explanation:
Customizing EEs in Automation Controller allows for task-specific runtime environments.


NEW QUESTION # 30
Generate a list of numbers from 1 to 10 using filters.

Answer:

Explanation:
- name: Generate number range hosts: localhost
tasks:
- name: Create range debug:
var: "{{ range(1, 11) | list }}"
Explanation:
The range filter generates sequential numbers, useful for looping or numerical data generation.


NEW QUESTION # 31
Deploy an EE to Kubernetes for distributed execution.

Answer:

Explanation:
1. Push the EE image to a container registry accessible by Kubernetes:
podman push my_execution_env:1.0 registry.example.com/my_execution_env:1.0
2. Create a Kubernetes Pod configuration:
apiVersion: v1
kind: Pod
metadata:
name: ansible-execution
spec:
containers:
- name: execution-env
image: registry.example.com/my_execution_env:1.0
command: ["ansible-playbook", "site.yml"]
volumeMounts:
- name: workspace mountPath: /workspace
volumes:
- name: workspace hostPath:
path: /path/to/workspace
3. Apply the configuration:
kubectl apply -f execution_env_pod.yaml
Explanation:
Deploying an EE to Kubernetes allows for scalable and distributed playbook execution across a cluster.


NEW QUESTION # 32
Use a delegated task to add a DNS entry for a host.

Answer:

Explanation:
- name: Add DNS entry hosts: web1
tasks:
- name: Update DNS records
command: echo "web1 IN A 192.168.1.10" >> /etc/dns/zone.file
delegate_to: dns_server
Explanation:
Delegating DNS management tasks to a specific server ensures centralized and consistent DNS configuration.


NEW QUESTION # 33
Configure a task to run as a specific user, admin, using the become_user directive.

Answer:

Explanation:
- 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.


NEW QUESTION # 34
Test machine credentials for AWS EC2 hosts.

Answer:

Explanation:
ansible all -m ping -i aws_ec2.yml --key-file ~/.ssh/aws_key.pem
Explanation:
Testing machine credentials ensures they work correctly for authenticating cloud-managed hosts.


NEW QUESTION # 35
Secure the database credentials using Ansible Vault.

Answer:

Explanation:
ansible-vault create db_creds.yml
Add the database credentials:
db_user: "admin"
db_password: "secure_password"
Explanation:
Storing sensitive information like database credentials in a Vault file ensures security and prevents unauthorized access.


NEW QUESTION # 36
Create a custom directory for inventory files and use it during a playbook execution.

Answer:

Explanation:
mkdir -p custom_inventory
echo "[web_servers]" > custom_inventory/inventory.ini
echo "web1 ansible_host=192.168.1.10" >> custom_inventory/inventory.ini ansible-playbook -i custom_inventory playbook.yml
Explanation:
Custom inventory directories organize host definitions for easier management, especially in large-scale deployments.


NEW QUESTION # 37
Create a playbook to stop execution after encountering an error in any task.

Answer:

Explanation:
- name: Stop on error hosts: all
tasks:
- name: Intentional failure
command: exit 1
ignore_errors: no
Explanation:
By default, Ansible stops on errors unless ignore_errors is set to yes. This ensures errors are addressed before proceeding.


NEW QUESTION # 38
Extract all unique keys from a dictionary using a filter.

Answer:

Explanation:
- name: Extract dictionary keys hosts: localhost
vars:
my_dict: name: John age: 30 city: London
tasks:
- name: Get keys debug:
var: "{{ my_dict.keys() | list }}"
Explanation:
Extracting dictionary keys helps in scenarios requiring iteration or analysis of available attributes.


NEW QUESTION # 39
......

100% Free Red Hat Certified Specialist EX374 Dumps PDF Demo Cert Guide Cover: https://realdumps.prep4sures.top/EX374-real-sheets.html