# Free RHCE practice questions

> 10 free RHCE practice questions with the correct answer and an explanation.

Page: https://devopscodelab.com/exams/redhat-ex294/free-practice-questions/
Practice exams: https://devopscodelab.com/exams/redhat-ex294/

### Question 1 of 10

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"
- 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:** B

**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 (choose 2)

Which two statements about Ansible modules are correct? (Choose two.)

- A. Modules are referenced by fully qualified collection names such as ansible.builtin.copy
- B. Every module must be listed under a collections keyword before it can be used
- C. Most modules are idempotent and report changed only when they modify the managed host
- D. Modules can run only on Linux managed nodes because they require a Python agent
- E. Modules are installed permanently on each managed node by the first playbook run

**Answer:** A, C

**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

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?

- A. Run a one-time playbook with -u root -k that creates devops, installs its public key and adds a sudoers drop-in file
- B. Copy the control node's /etc/sudoers file to every managed node with scp before running any playbook
- C. Edit ansible.cfg to set remote_user = devops and run the normal playbooks, which create the account themselves
- D. Set ansible_connection=local for the new nodes so tasks run without needing any remote account

**Answer:** A

**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

An ansible-navigator.yml file must make navigator use the project inventory file ./inventory and the project ./ansible.cfg explicitly. Which snippet is correct?

- A. ansible-navigator:
  ansible:
    config:
      path: ./ansible.cfg
    inventory:
      entries:
        - ./inventory
- B. ansible-navigator:
  defaults:
    config_file: ./ansible.cfg
    hosts: ./inventory
- C. ansible-navigator:
  execution-environment:
    config: ./ansible.cfg
    inventory: ./inventory
- D. ansible-navigator:
  ansible-config: ./ansible.cfg
  inventory-file: ./inventory

**Answer:** A

**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

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?

- A. Right-click the playbook and choose the command to run it with ansible-navigator
- B. Use the Source Control view and select Run from the commit menu
- C. Open the Extensions view and click Run next to the Ansible extension
- D. Press F5, because the VS Code debugger runs the open playbook with ansible-navigator by default

**Answer:** A

**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

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?

- A. until: result.status == 200
retries: 12
delay: 10
- B. until: result.status != 200
retries: 10
delay: 12
- C. loop: "{{ range(12) }}"
when: result.status == 200
pause: 10
- D. retries: 12
delay: 10
failed_when: result.status == 200

**Answer:** A

**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

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?

- A. Set the systemd default target to reboot.target through ansible.builtin.service
- B. Notify a handler that runs ansible.builtin.shell: reboot with async and poll set to zero
- C. Run ansible.builtin.command: shutdown -r now followed by a pause task of five minutes
- D. Register the dnf result and run ansible.builtin.reboot with when: result is changed

**Answer:** D

**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

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?

- A. ansible-galaxy collection install -r collections/requirements.yml -p /usr/share/ansible
- B. ansible-galaxy role install -r collections/requirements.yml -p collections
- C. ansible-galaxy collection download -r collections/requirements.yml -p collections
- D. ansible-galaxy collection install -r collections/requirements.yml -p collections

**Answer:** D

**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

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

**Answer:** D

**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

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

**Answer:** D

**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.

Ready for a timed run? Take the free 15-question RHCE mini exam: https://devopscodelab.com/app/exams/redhat-ex294/mini/

DevOpsCode Lab is not affiliated with Red Hat. RHCE and related names are trademarks of their owners. We write every question ourselves; these are not real exam questions.
