Skip to content

Commit

Permalink
Add templating support for nmstate defined networking configuration
Browse files Browse the repository at this point in the history
* Added `edpm_network_config_nmstate_template` variable
* Added sample `templates/system_role_nmstate/single_nic_vlans.j2` template file
* Fixed `nmstate` molecule scenario for `edpm_network_config` role

Signed-off-by: Roberto Alfieri <[email protected]>
  • Loading branch information
rebtoor committed Jul 28, 2023
1 parent 670640e commit f6e6003
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions roles/edpm_network_config/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ 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_nmstate_template: templates/system_role_nmstate/single_nic_vlans.j2
edpm_network_config_override: {}
edpm_bond_interface_ovs_options: "bond_mode=active-backup"
8 changes: 1 addition & 7 deletions roles/edpm_network_config/molecule/nmstate/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
vars:
edpm_network_config_tool: nmstate
network_provider: nm
network_state:
interfaces:
- name: dummy0
type: dummy
state: down
ipv4:
enabled: false
edpm_network_config_nmstate_template: ./dummy_config.j2
roles:
- role: "osp.edpm.edpm_network_config"
7 changes: 7 additions & 0 deletions roles/edpm_network_config/molecule/nmstate/dummy_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
interfaces:
- name: dummy0
type: dummy
state: down
ipv4:
enabled: false
3 changes: 3 additions & 0 deletions roles/edpm_network_config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
name: NetworkManager
state: restarted
when: nm_ovs_status.changed
- name: Render network_config variable
ansible.builtin.set_fact:
network_config: "{{ lookup('template', edpm_network_config_nmstate_template ) }}"
- name: Load system-roles.network tasks [nmstate]
ansible.builtin.include_role:
name: "{{ systemrolename }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
{% set mtu_list = [ctlplane_mtu] %}
{% for network in role_networks %}
{{ mtu_list.append(lookup('vars', networks_lower[network] ~ '_mtu')) }}
{%- endfor %}
{% set min_viable_mtu = mtu_list | max %}
dns-resolver:
config:
search: {{ dns_search_domains }}
server: {{ ctlplane_dns_nameservers }}
interfaces:
- name: {{ neutron_public_interface_name }}
type: ethernet
state: up
- name: {{ neutron_physical_bridge_name }}
type: ovs-interface
state: up
mtu: {{ min_viable_mtu }}
ipv4:
enabled: true
address:
- ip: {{ ctlplane_ip }}
prefix-length: {{ ctlplane_subnet_cidr }}
{% for network in role_networks %}
- name: {{ "vlan" ~ lookup('vars', networks_lower[network] ~ '_vlan_id') }}
type: ovs-interface
state: up
mtu: {{ lookup('vars', networks_lower[network] ~ '_mtu') }}
ipv4:
enabled: true
address:
- ip: {{ lookup('vars', networks_lower[network] ~ '_ip') }}
prefix-length: {{ lookup('vars', networks_lower[network] ~ '_cidr') }}
{% endfor %}
- name: {{ neutron_physical_bridge_name }}
type: ovs-bridge
bridge:
options:
fail-mode: standalone
port:
- name: {{ neutron_public_interface_name }}
- name: {{ neutron_physical_bridge_name }}
{% for network in role_networks %}
- name: {{ "vlan" ~ lookup('vars', networks_lower[network] ~ '_vlan_id') }}
vlan:
mode: access
tag: {{ lookup('vars', networks_lower[network] ~ '_vlan_id') }}
{% endfor %}
routes:
config:
- destination: {{ ctlplane_host_routes.ip_netmask }}
next-hop-address: {{ ctlplane_host_routes.next_hop }}
next-hop-interface: {{ neutron_physical_bridge_name }}
{% for network in role_neworks %}
- destination: {{ lookup('vars', networks_lower[network] ~ '_host_routes').ip_netmask }}
next-hop-address: {{ lookup('vars', networks_lower[network] ~ '_host_routes').next_hop }}
next-hop-interface: {{ "vlan" ~ lookup('vars', networks_lower[network] ~ '_vlan_id') }}
{% endfor %}

0 comments on commit f6e6003

Please sign in to comment.