Welche Gründe sprechen für das Ansible Copy-Modul, um einzelne Dateienzeilen zu ändern?

What are the reasons for using the Ansible Copy module to change individual file lines?

It is often necessary to change individual file lines. However, many lineinfile or blockinfile modules are used for this purpose. However, practical experience shows that these modules should not be used if files are to be changed with them. In this case, it is better to use the template or copy module. In particular, to manage not only individual lines, but the entire file. There are two reasons for this:

  • When using lineinfile, regex must often be used. This results in the following problems: The use of regex is often complicated and people who then use playbooks must be familiar with regex.
  • The programmer himself must know and be able to remember that this particular line in this one configuration file is managed by Ansible.

If you manage the entire file with an Ansible template, you can use theansible_managed variable to make it clear that the file is under Ansible control. Another advantage is that you can use a variable for the selinux-state and simply change it on servers where selinux should not be in the enforcing state.

Suitable training courses/seminars: