RHCE
Free RHCE practice questions
10 questions from our RHCE practice tests, each with the correct answer and a written explanation. Read them with the answers shown, or switch to quiz mode and answer first.
Question 1 of 10, Understand core components of Ansible
A task should fail when the output of a command contains the word ERROR, even though the command itself always exits with status 0. Which task configuration implements this?
- A- ansible.builtin.command: /usr/local/bin/check-app register: check ignore_errors: "'ERROR' in check.stdout"
- B- ansible.builtin.command: /usr/local/bin/check-app register: check failed_when: "'ERROR' in check.stdout" Correct answer
- C- ansible.builtin.command: /usr/local/bin/check-app register: check until: "'ERROR' not in check.stdout"
- D- ansible.builtin.command: /usr/local/bin/check-app register: check changed_when: "'ERROR' in check.stdout"
Answer and explanation: failed_when replaces the default failure condition with a custom expression, so the task fails when the registered stdout contains ERROR. changed_when only alters the changed status, ignore_errors would suppress failures rather than create one, and until retries the task until the condition is true and then ends successfully or with a retry failure rather than evaluating the output once.
Question 2 of 10, Understand core components of Ansible. Choose 2.
Which two statements about Ansible modules are correct? (Choose two.)
- AModules are referenced by fully qualified collection names such as ansible.builtin.copy Correct answer
- BEvery module must be listed under a collections keyword before it can be used
- CMost modules are idempotent and report changed only when they modify the managed host Correct answer
- DModules can run only on Linux managed nodes because they require a Python agent
- EModules are installed permanently on each managed node by the first playbook run
Answer and explanation: Well-written modules check the current state and only change and report changed when needed, and current practice references them by FQCN such as ansible.builtin.copy. Ansible copies module code temporarily and removes it after execution, it has no persistent agent, and Windows hosts are managed with PowerShell-based modules. The collections keyword is optional when FQCNs are used.
Question 3 of 10, Configure Ansible and managed nodes
New managed nodes have only the root account with password login, and the automation user devops must be created and authorised before normal playbooks can run. Which bootstrap approach is appropriate?
- ARun a one-time playbook with -u root -k that creates devops, installs its public key and adds a sudoers drop-in file Correct answer
- BCopy the control node's /etc/sudoers file to every managed node with scp before running any playbook
- CEdit ansible.cfg to set remote_user = devops and run the normal playbooks, which create the account themselves
- DSet ansible_connection=local for the new nodes so tasks run without needing any remote account
Answer and explanation: A bootstrap playbook connecting once as root with a password prompt can create the user, distribute the key with authorized_key and grant sudo through /etc/sudoers.d, after which normal runs use devops. The normal playbooks cannot log in as a user that does not exist yet, overwriting sudoers with another system's file is unsafe and does not create the user, and local connections run on the control node rather than the new hosts.
Question 4 of 10, Configure Ansible and managed nodes
An ansible-navigator.yml file must make navigator use the project inventory file ./inventory and the project ./ansible.cfg explicitly. Which snippet is correct?
- Aansible-navigator: ansible: config: path: ./ansible.cfg inventory: entries: - ./inventory Correct answer
- Bansible-navigator: defaults: config_file: ./ansible.cfg hosts: ./inventory
- Cansible-navigator: execution-environment: config: ./ansible.cfg inventory: ./inventory
- Dansible-navigator: ansible-config: ./ansible.cfg inventory-file: ./inventory
Answer and explanation: Navigator groups Ansible-related settings under ansible, with config.path for the configuration file and inventory.entries for one or more inventory sources. ansible-config and inventory-file are not navigator keys, execution-environment configures the container rather than Ansible files, and a defaults section with config_file and hosts belongs to neither navigator nor ansible.cfg syntax.
Question 5 of 10, Run playbooks with ansible-navigator, Git and VS Code
In VS Code with the Red Hat Ansible extension installed, how does a developer run the currently open playbook with ansible-navigator from the editor?
- ARight-click the playbook and choose the command to run it with ansible-navigator Correct answer
- BUse the Source Control view and select Run from the commit menu
- COpen the Extensions view and click Run next to the Ansible extension
- DPress F5, because the VS Code debugger runs the open playbook with ansible-navigator by default
Answer and explanation: The Ansible extension adds commands, available from the editor context menu and the Command Palette, to run the current playbook with ansible-navigator or ansible-playbook. F5 starts a debug configuration rather than the extension's run command, the Source Control view handles Git, and the Extensions view manages extensions rather than running playbooks.
Question 6 of 10, Create Ansible plays and playbooks
A task registers the output of an API health check and must keep retrying every 10 seconds, up to 12 times, until the registered status equals 200. Which keywords implement this?
- Auntil: result.status == 200 retries: 12 delay: 10 Correct answer
- Buntil: result.status != 200 retries: 10 delay: 12
- Cloop: "{{ range(12) }}" when: result.status == 200 pause: 10
- Dretries: 12 delay: 10 failed_when: result.status == 200
Answer and explanation: until repeats the task until the condition is true, retries sets the maximum number of attempts and delay sets the seconds between them. A loop with when evaluates the condition before each fixed iteration rather than retrying, and pause is not a task keyword. Combining retries with failed_when on success makes the task fail on a healthy result, and the last option swaps the values and stops on the wrong condition.
Question 7 of 10, Create Ansible plays and playbooks
A task updates the kernel and, if anything changed, the host must be rebooted and Ansible must wait until it is back before continuing with the next task. Which approach is simplest and fully supported?
- ASet the systemd default target to reboot.target through ansible.builtin.service
- BNotify a handler that runs ansible.builtin.shell: reboot with async and poll set to zero
- CRun ansible.builtin.command: shutdown -r now followed by a pause task of five minutes
- DRegister the dnf result and run ansible.builtin.reboot with when: result is changed Correct answer
Answer and explanation: The reboot module reboots the host, waits for it to go down and come back, and then verifies connectivity before the play continues, and the changed test on the registered result limits it to hosts that were updated. A handler would wait until the end of the section, and shell reboot with async does not verify the return. A fixed pause is unreliable and the service module cannot set the default target.
Question 8 of 10, Use roles and Ansible Content Collections
A playbook must use modules from collections installed in the project subdirectory collections, and the run must work with both ansible-playbook and ansible-navigator. Which install command puts them in the right place?
- Aansible-galaxy collection install -r collections/requirements.yml -p /usr/share/ansible
- Bansible-galaxy role install -r collections/requirements.yml -p collections
- Cansible-galaxy collection download -r collections/requirements.yml -p collections
- Dansible-galaxy collection install -r collections/requirements.yml -p collections Correct answer
Answer and explanation: Installing with -p collections creates collections/ansible_collections in the project, and Ansible searches a collections directory adjacent to the playbook, which also gets mounted into the execution environment by ansible-navigator. /usr/share/ansible on the control node is not visible inside the container, role install ignores the collections list, and collection download only fetches tarballs without installing them.
Question 9 of 10, Automate standard RHCSA tasks using Ansible modules
A user account must be locked so that it can no longer log in with a password, but it must not be deleted. Which task does this?
- A- ansible.builtin.user: name: contractor expires: 0 remove: true
- B- ansible.builtin.user: name: contractor state: absent force: false
- C- ansible.builtin.user: name: contractor password: '' update_password: always
- D- ansible.builtin.user: name: contractor password_lock: true Correct answer
Answer and explanation: password_lock: true locks the password, like usermod -L, while keeping the account. state: absent deletes the account, setting an empty password removes it rather than locking and may even allow password-less logins depending on configuration, and remove only has an effect together with state: absent while expires: 0 disables the account by expiry rather than locking the password.
Question 10 of 10, Manage content with templates and Ansible Vault
A template writes the sshd configuration, and an invalid file would lock administrators out. Which task deploys it while refusing to install a file that fails the sshd syntax check?
- A- ansible.builtin.template: src: sshd_config.j2 dest: /etc/ssh/sshd_config notify: sshd -t mode: '0600'
- B- ansible.builtin.template: src: sshd_config.j2 dest: /etc/ssh/sshd_config check_mode: true mode: '0600'
- C- ansible.builtin.template: src: sshd_config.j2 dest: /etc/ssh/sshd_config backup: true force: false
- D- ansible.builtin.template: src: sshd_config.j2 dest: /etc/ssh/sshd_config validate: /usr/sbin/sshd -t -f %s Correct answer
Answer and explanation: validate runs the given command against the rendered temporary file, with %s replaced by its path, and the file is only moved into place if the command succeeds. backup keeps a copy but still installs a broken file and force: false skips updates to an existing file, check_mode prevents any change, and notifying a handler named sshd -t runs after the file has already been installed.