Free RHCE Automation and Deployment Questions and Answers — Questions and Answers
Question 1: Which configurations in ansible.cfg are used for privilege escalation?
- privilege, escalate_method, escalate_user, ask_for_become
- become, method_become, user_become, ask_become_pass
- become, become_method, become_user, become_ask_pass (Correct answer)
- escalation, method_privilege, user_privilege, ask_for_privilege
Correct answer: become, become_method, become_user, become_ask_pass
In Ansible, privilege escalation, often referred to as 'become,' is configured using specific parameters in `ansible.cfg`. These include `become` to enable escalation, `become_method` for the method (e.g., sudo), `become_user` for the target user, and `become_ask_pass` to prompt for a password. These settings collectively define how Ansible gains elevated permissions on managed hosts.
Question 2: What command syntax is used to perform a syntax check on an Ansible playbook?
- ansible-playbook check playbook.yml
- ansible-check playbook.yml
- ansible-playbook --check playbook.yml
- ansible-playbook --syntax-check playbook.yml (Correct answer)
Correct answer: ansible-playbook --syntax-check playbook.yml
The command `ansible-playbook --syntax-check playbook.yml` is used to validate the YAML syntax of an Ansible playbook. This command parses the playbook for structural correctness without executing any tasks on target hosts. It is a crucial step for identifying and correcting syntax errors early, preventing potential failures during actual playbook execution.
Question 3: What command syntax is used to perform a dry run (check mode) of an Ansible playbook without making changes?
- ansible-playbook -D playbook.yml
- ansible-playbook -C playbook.yml (Correct answer)
- ansible-playbook --dry-run playbook.yml
- ansible-playbook --pretend playbook.yml
Correct answer: ansible-playbook -C playbook.yml
The `ansible-playbook -C playbook.yml` command, where `-C` is shorthand for `--check`, performs a 'dry run' or 'check mode' of an Ansible playbook. In this mode, Ansible reports what changes *would* be made to the target systems without actually implementing them. This is invaluable for testing playbooks and understanding their potential impact before making any permanent modifications.
Question 4: How do you save the output from an Ansible module to a variable?
- register: var_name (Correct answer)
- var_name = ansible_module module_name
- save: var_name = module_name
- ansible save var_name module_name
Correct answer: register: var_name
In Ansible, the `register` keyword is used to capture the output of a task and store it in a variable. This allows subsequent tasks in the playbook to access and utilize the information returned by the preceding module. For example, the output of a shell command or a module's state can be registered and then used for conditional logic or further processing.
Question 5: How do you output or display the value of a variable in Ansible?
- print: var_name
- log: var_name
- echo var_name
- debug: var=var_name (Correct answer)
Correct answer: debug: var=var_name
The `debug` module in Ansible is specifically designed to output variables or messages during playbook execution. Using `debug: var=var_name` will display the current value of the specified variable to the console. This is an essential tool for debugging playbooks, verifying variable contents, and tracing execution flow.
Question 6: What keyword is used for looping over a list (which can be a variable) in Ansible?
- loop (Correct answer)
- cycle
- iterate
- repeat
Correct answer: loop
The `loop` keyword in Ansible is used to iterate over lists, dictionaries, or sequences of items within a task. It allows the same task to be executed multiple times, once for each item in the specified list or variable. This significantly simplifies and condenses playbooks when performing repetitive operations on multiple similar entities.
Question 7: Which Ansible configuration groups are commonly used to define default settings and privilege escalation options?
- [global], [escalation]
- [common], [privilege]
- [default], [escalation]
- [defaults], [privilege_escalation] (Correct answer)
Correct answer: [defaults], [privilege_escalation]
In the `ansible.cfg` file, the `[defaults]` section is used to define general configuration options that apply globally to Ansible operations. The `[privilege_escalation]` section (or `[become]` in newer versions) is specifically where settings related to privilege escalation, such as `become_method` and `become_user`, are configured. These sections enable centralized management of Ansible's behavior and security settings.
Which configurations in ansible.cfg are used for privilege escalation?