mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-27 04:50:49 +00:00
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>
103 lines
3 KiB
YAML
103 lines
3 KiB
YAML
# SPDX-License-Identifier: BSD-3-Clause
|
|
# get service facts, used in defaults/main.yml
|
|
---
|
|
- name: Check which services are running
|
|
service_facts:
|
|
no_log: true
|
|
|
|
# needed for ansible_facts.packages
|
|
- name: Check which packages are installed
|
|
package_facts:
|
|
no_log: true
|
|
|
|
- name: Print network provider
|
|
debug:
|
|
msg: "Using network provider: {{ network_provider }}"
|
|
|
|
# Depending on the plugins, checking installed packages might be slow
|
|
# for example subscription manager might slow this down
|
|
# Therefore install packages only when rpm does not find them
|
|
- name: Install packages
|
|
package:
|
|
name: "{{ network_packages }}"
|
|
state: present
|
|
when:
|
|
- not network_packages is subset(ansible_facts.packages.keys())
|
|
register: __network_package_install
|
|
|
|
# If network packages changed and wireless or team connections are specified,
|
|
# NetworkManager must be restarted
|
|
- name: Restart NetworkManager due to wireless or team interfaces
|
|
service:
|
|
name: NetworkManager
|
|
state: restarted
|
|
when:
|
|
- __network_wireless_connections_defined
|
|
or __network_team_connections_defined
|
|
- network_provider == "nm"
|
|
- network_allow_restart
|
|
# ansible-lint wants this to be a handler, but this is not appropriate as
|
|
# NetworkManager must be restarted prior to the connections being created.
|
|
# see (https://docs.ansible.com/ansible-lint/rules/default_rules.html)
|
|
- __network_package_install.changed # noqa 503
|
|
|
|
- name: Enable and start NetworkManager
|
|
service:
|
|
name: "{{ network_service_name }}"
|
|
state: started
|
|
enabled: true
|
|
when:
|
|
- network_provider == "nm"
|
|
no_log: true
|
|
|
|
# If any 802.1x connections are used, the wpa_supplicant
|
|
# service is required to be running
|
|
- name: Enable and start wpa_supplicant
|
|
service:
|
|
name: wpa_supplicant
|
|
state: started
|
|
enabled: true
|
|
when:
|
|
- network_provider == "nm"
|
|
- __network_wpa_supplicant_required
|
|
|
|
- name: Enable network service
|
|
service:
|
|
name: "{{ network_service_name }}"
|
|
enabled: true
|
|
when:
|
|
- network_provider == "initscripts"
|
|
no_log: true
|
|
|
|
- name: Ensure initscripts network file dependency is present
|
|
copy:
|
|
dest: /etc/sysconfig/network
|
|
content: "# Created by network system role"
|
|
mode: "0644"
|
|
force: false
|
|
when:
|
|
- network_provider == "initscripts"
|
|
|
|
- name: Configure networking connection profiles
|
|
network_connections:
|
|
provider: "{{ network_provider | mandatory }}"
|
|
ignore_errors: "{{ network_ignore_errors | default(omit) }}"
|
|
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
|
|
debug:
|
|
var: __network_connections_result.stderr_lines
|
|
|
|
- name: Show debug messages
|
|
debug:
|
|
var: __network_connections_result
|
|
verbosity: 1
|
|
|
|
- name: Re-test connectivity
|
|
ping:
|