問題1
Use a survey to capture runtime inputs for a job template.
Use a survey to capture runtime inputs for a job template.
正確答案:
1. Edit the job template and enable Survey.
2. Add survey questions:
o Name: Environment
o Type: Multiple Choice
o Options: Dev, Test, Prod
3. Save and launch the job.
Explanation:
Surveys provide a user-friendly way to collect runtime inputs, enabling customization of playbook execution.
2. Add survey questions:
o Name: Environment
o Type: Multiple Choice
o Options: Dev, Test, Prod
3. Save and launch the job.
Explanation:
Surveys provide a user-friendly way to collect runtime inputs, enabling customization of playbook execution.
問題2
Loop through a YAML dictionary to display keys and their values.
Loop through a YAML dictionary to display keys and their values.
正確答案:
- 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.
問題3
Publish the collection to Ansible Galaxy.
Publish the collection to Ansible Galaxy.
正確答案:
ansible-galaxy collection publish my_namespace-my_collection-1.0.0.tar.gz --api-key <your_galaxy_api_key>
Explanation:
The publish command uploads the collection to Ansible Galaxy, making it accessible to the community or other users.
Explanation:
The publish command uploads the collection to Ansible Galaxy, making it accessible to the community or other users.
問題4
Create a playbook to skip tasks for hosts with ansible_distribution set to CentOS.
Create a playbook to skip tasks for hosts with ansible_distribution set to CentOS.
正確答案:
- name: Skip CentOS hosts: all
tasks:
- name: Run on non-CentOS debug:
msg: "This is not CentOS"
when: ansible_facts['distribution'] != "CentOS"
Explanation:
Skipping tasks based on conditions ensures compatibility and avoids unnecessary errors on unsupported hosts.
tasks:
- name: Run on non-CentOS debug:
msg: "This is not CentOS"
when: ansible_facts['distribution'] != "CentOS"
Explanation:
Skipping tasks based on conditions ensures compatibility and avoids unnecessary errors on unsupported hosts.
問題5
Execute a task on the control node only if a condition on web1 is met.
Execute a task on the control node only if a condition on web1 is met.
正確答案:
- name: Conditional delegation hosts: web1
tasks:
- name: Check file existence stat:
path: /tmp/flag.txt register: flag_check
- name: Notify control node
command: echo "Flag exists"
delegate_to: localhost
when: flag_check.stat.exists
Explanation:
Delegation combined with conditional logic ensures tasks are executed only under specific circumstances.
tasks:
- name: Check file existence stat:
path: /tmp/flag.txt register: flag_check
- name: Notify control node
command: echo "Flag exists"
delegate_to: localhost
when: flag_check.stat.exists
Explanation:
Delegation combined with conditional logic ensures tasks are executed only under specific circumstances.
問題6
Filter a list of numbers to include only even numbers.
Filter a list of numbers to include only even numbers.
正確答案:
- name: Filter even numbers hosts: localhost
vars:
numbers: [1, 2, 3, 4, 5, 6] tasks:
- name: Get even numbers debug:
var: "{{ numbers | select('even') | list }}"
Explanation:
The select filter applies a condition, such as even, to extract specific elements from a list.
vars:
numbers: [1, 2, 3, 4, 5, 6] tasks:
- name: Get even numbers debug:
var: "{{ numbers | select('even') | list }}"
Explanation:
The select filter applies a condition, such as even, to extract specific elements from a list.
問題7
Set up notifications for job failures in Automation Controller.
Set up notifications for job failures in Automation Controller.
正確答案:
1. Navigate to Notifications and click Add.
2. Choose Type: Slack.
3. Configure Slack details and associate it with a job template.
4. Set the trigger to On Failure.
Explanation:
Notifications improve responsiveness by alerting users of job failures in real time.
2. Choose Type: Slack.
3. Configure Slack details and associate it with a job template.
4. Set the trigger to On Failure.
Explanation:
Notifications improve responsiveness by alerting users of job failures in real time.
問題8
Perform a delegated task to update firewall rules on a specific host.
Perform a delegated task to update firewall rules on a specific host.
正確答案:
- name: Update firewall rules hosts: web1
tasks:
- name: Add firewall rule on db1
command: firewall-cmd --add-port=8080/tcp
delegate_to: db1
Explanation:
Delegating firewall rule updates ensures secure and host-specific configurations without unnecessary context switching.
tasks:
- name: Add firewall rule on db1
command: firewall-cmd --add-port=8080/tcp
delegate_to: db1
Explanation:
Delegating firewall rule updates ensures secure and host-specific configurations without unnecessary context switching.
問題9
Uninstall a collection from your local environment.
Uninstall a collection from your local environment.
正確答案:
ansible-galaxy collection remove my_namespace.my_collection
Explanation:
Removing unnecessary collections keeps the Ansible environment clean and avoids conflicts.
Explanation:
Removing unnecessary collections keeps the Ansible environment clean and avoids conflicts.
問題10
Split a list into chunks of a specified size.
Split a list into chunks of a specified size.
正確答案:
- name: Chunk list hosts: localhost vars:
items: [1, 2, 3, 4, 5, 6] tasks:
- name: Create chunks
debug:
var: "{{ items | batch(2) }}"
Explanation:
The batch filter splits a list into smaller groups of specified size, useful for parallel processing.
items: [1, 2, 3, 4, 5, 6] tasks:
- name: Create chunks
debug:
var: "{{ items | batch(2) }}"
Explanation:
The batch filter splits a list into smaller groups of specified size, useful for parallel processing.
問題11
Inspect the logs of an EE build process.
Inspect the logs of an EE build process.
正確答案:
podman logs $(podman ps -aq --filter ancestor=my_execution_env:1.0)
Explanation:
Inspecting logs helps troubleshoot issues that occur during the build process, ensuring a functional EE.
Explanation:
Inspecting logs helps troubleshoot issues that occur during the build process, ensuring a functional EE.
問題12
Create an advanced inventory with host-specific variables.
Create an advanced inventory with host-specific variables.
正確答案:
# inventory_advanced.yml all:
hosts:
web1:
ansible_host: 192.168.1.10
http_port: 80 db1:
ansible_host: 192.168.1.20
db_port: 3306
Explanation:
Advanced inventories define host-specific variables, enabling fine-grained control over task execution.
hosts:
web1:
ansible_host: 192.168.1.10
http_port: 80 db1:
ansible_host: 192.168.1.20
db_port: 3306
Explanation:
Advanced inventories define host-specific variables, enabling fine-grained control over task execution.
問題13
Write a playbook to execute a task based on a host's operating system version.
Write a playbook to execute a task based on a host's operating system version.
正確答案:
- name: OS-specific task hosts: all
tasks:
- name: Task for Ubuntu
command: echo "Running on Ubuntu"
when: ansible_facts['distribution'] == "Ubuntu"
Explanation:
Conditional execution based on facts like OS version tailors tasks for specific environments, improving compatibility.
tasks:
- name: Task for Ubuntu
command: echo "Running on Ubuntu"
when: ansible_facts['distribution'] == "Ubuntu"
Explanation:
Conditional execution based on facts like OS version tailors tasks for specific environments, improving compatibility.
問題14
Create a source control credential in Automation Controller.
Create a source control credential in Automation Controller.
正確答案:
1. Navigate to Credentials.
2. Add a new credential: o Type: Source Control o Username: git_user
o Password/Token: secure_token
3. Save the credential.
Explanation:
Source control credentials in Automation Controller enable automated access to repositories for pulling playbooks or roles.
2. Add a new credential: o Type: Source Control o Username: git_user
o Password/Token: secure_token
3. Save the credential.
Explanation:
Source control credentials in Automation Controller enable automated access to repositories for pulling playbooks or roles.
問題15
Secure the database credentials using Ansible Vault.
Secure the database credentials using Ansible Vault.
正確答案:
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.
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.