Red Hat Certified Engineer RHCE · Free Practice Question Medium

Question 7

You are tasked with copying a configuration file from the control node to multiple managed nodes. How would you write an Ansible playbook using the copy module to deploy the configuration file to all managed nodes?

  • A

    Copying a Configuration File to Multiple Managed Nodes Using Ansible
    Create an Ansible playbook with the copy module:

    This deploys the configuration file from the control node to all managed nodes.

  • B

    This is a performance based question and not multiple choice.  Therefore the answer is in #1.  If you require additional explanation, please ask your question in the Q&A section.

Reveal correct answer

Correct answer: A

A.

In this solution, an Ansible playbook is written using the copy module to copy a configuration file from the control node to multiple managed nodes. The ansible.builtin.copy module is used to manage the copying process. In the playbook, the source file (/path/to/config_file.conf) is specified along with the destination directory (/etc/app/config_file.conf). The mode: '0644' ensures that the copied file has the correct permissions, allowing the owner to read and write the file, while the group and others can only read it. This playbook will ensure that the configuration file is deployed consistently across all the managed nodes.

Line-by-Line Explanation

  1. - hosts: all

    • This specifies that the playbook will run on all hosts defined in the Ansible inventory. It applies the task to all managed nodes.

  2. tasks:

    • This section defines the tasks to be executed on the target hosts.

  3. - name: Copy configuration file to managed nodes

    • The description of the task. It indicates that the task's purpose is to copy a configuration file to the managed nodes.

  4. ansible.builtin.copy:

    • This uses the copy module from Ansible to copy files from the control node to the managed nodes.

  5. src: /path/to/config_file.conf

    • The path to the source configuration file on the control node. This is the file that will be copied.

  6. dest: /etc/app/config_file.conf

    • The destination path where the configuration file will be copied on the managed nodes. The file will be placed in the /etc/app/ directory.

  7. mode: '0644'

    • Sets the permissions of the copied file. 0644 allows the file owner to read and write the file, while the group and others can only read the file.

This playbook ensures that the configuration file is copied to multiple managed nodes, applying the correct file permissions, and is a simple, efficient method for deploying configuration files across multiple machines in a controlled and consistent manner.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need