Skip to content

Commit

Permalink
Add templating support for nmstate defined networking configuration
Browse files Browse the repository at this point in the history
* Fixed `nmstate` molecule scenario for `edpm_network_config` role

Signed-off-by: Roberto Alfieri <[email protected]>
  • Loading branch information
rebtoor committed Aug 3, 2023
1 parent 670640e commit 8f27080
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion roles/edpm_network_config/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ edpm_network_config_nmstate: false
edpm_network_config_os_net_config_mappings: {}
edpm_network_config_safe_defaults: true
edpm_network_config_with_ansible: true
edpm_network_config_template: templates/single_nic_vlans/single_nic_vlans.j2
edpm_network_config_template: ""
edpm_network_config_override: {}
edpm_bond_interface_ovs_options: "bond_mode=active-backup"
6 changes: 4 additions & 2 deletions roles/edpm_network_config/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

- name: Prepare
hosts: all
become: true
roles:
- role: test_deps
test_deps_setup_edpm: true
Expand All @@ -26,12 +27,13 @@

tasks:
- name: Ensure legacy scripts installed
become: true
ansible.builtin.package:
name: network-scripts
state: present
when:
- ansible_facts['distribution_major_version'] is version('8', '==')
- name: Create a dummy network interface
become: true
ansible.builtin.command: "ip link add dummy0 type dummy"
register: ip_command_output
changed_when: ip_command_output.rc == 0
failed_when: ip_command_output.rc != 0
15 changes: 7 additions & 8 deletions roles/edpm_network_config/molecule/nmstate/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
hosts: all
vars:
edpm_network_config_tool: nmstate
network_provider: nm
network_state:
edpm_network_config_template: |
interfaces:
- name: dummy0
type: dummy
state: down
ipv4:
enabled: false
- name: dummy0
type: dummy
state: up
ipv4:
enabled: false
roles:
- role: "osp.edpm.edpm_network_config"
- role: osp.edpm.edpm_network_config
13 changes: 8 additions & 5 deletions roles/edpm_network_config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,34 @@
# under the License.

- name: Configure network with network role from system roles [nmstate]
when: edpm_network_config_tool == 'nmstate'
block:
- name: Retrieve role name [nmstate]
ansible.builtin.set_fact:
systemrolename:
"{%- if ansible_facts['distribution'] == 'RedHat' -%}
systemrolename: >-
{%- if ansible_facts['distribution'] == 'RedHat' -%}
redhat.rhel
{%- else -%}
fedora.linux
{%- endif -%}
_system_roles.network"
_system_roles.network
delegate_to: localhost
- name: Install OVS NetworkManager plugin [nmstate]
ansible.builtin.dnf:
name: NetworkManager-ovs
state: latest
state: present
register: nm_ovs_status
- name: Restart NetworkManager after plugin installation [nmstate]
ansible.builtin.systemd:
name: NetworkManager
state: restarted
when: nm_ovs_status.changed
- name: Render network_config variable
ansible.builtin.set_fact:
network_state: "{{ edpm_network_config_template | from_yaml }}"
- name: Load system-roles.network tasks [nmstate]
ansible.builtin.include_role:
name: "{{ systemrolename }}"
when: edpm_network_config_tool == 'nmstate'

- name: Load edpm_network_config tasks [os-net-config]
ansible.builtin.include_tasks:
Expand Down
4 changes: 2 additions & 2 deletions roles/edpm_network_config/tasks/network_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
become: true
when:
- ansible_facts.selinux.status == "enabled"
sefcontext:
community.general.sefcontext:
target: "/var/lib/edpm-config(/.*)?"
setype: container_file_t
selevel: s0
Expand All @@ -42,7 +42,7 @@
become: true
ansible.builtin.dnf:
name: os-net-config
state: latest
state: present

- name: Ensure /var/lib/edpm-config directory exists
become: true
Expand Down

0 comments on commit 8f27080

Please sign in to comment.