System Roles should consistently use ansible_managed in configuration files it manages

bz#2044640

The network role create an ifcfg file for initscripts. The file
used to append a comment "# this file was created by ansible".
This patch replaces the proprietary string with the ansible
standard {{ ansible_managed }} to adjust to the other system
roles.

For the implementation, it borrowed the method from kernel_settings,
getting the ansible managed comment using the get_ansible_managed.j2
template and pass the comment to network_connections which is added
to the ifcfg file.

In case network_provider is nm, the comment is not added to the
ifcfg file as the file is not managed by Ansible.

Note: the required parameter name to pass the ansible managed comment
to the network_connection module is "__header".

Do not use get_ansible_managed.j2 in the test scripts, but use a
hardcoded ansible managed comment to simplify the tests.

tests/tasks/get_profile_stat.yml: replace the '=' style with the YAML
notation in set_fact.

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
This commit is contained in:
Noriko Hosoi 2022-02-11 08:18:30 -08:00 committed by Gris Ge
parent 61423ed36f
commit 79b39792e4
8 changed files with 46 additions and 6 deletions

View file

@ -85,6 +85,9 @@
force_state_change: "{{ network_force_state_change | default(omit) }}"
connections: "{{ network_connections | default([]) }}"
__debug_flags: "{{ __network_debug_flags | default(omit) }}"
__header: "{{ __lsr_ansible_managed }}"
vars:
__lsr_ansible_managed: "{{ lookup('template', 'get_ansible_managed.j2') }}"
register: __network_connections_result
- name: Show stderr messages