Skip to content

Commit

Permalink
add ethernet template for network manager
Browse files Browse the repository at this point in the history
  • Loading branch information
bbezak committed Oct 7, 2022
1 parent 31ce70e commit 8aad4f9
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 9 deletions.
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interfaces_pkgs:
- NetworkManager-initscripts-updown
interfaces_net_path:
debian: /etc/network/interfaces.d
redhat: /etc/sysconfig/network-scripts
redhat: "{% if interfaces_use_networkmanager | bool %}/etc/NetworkManager/system-connections{% else %}/etc/sysconfig/network-scripts{% endif %}"

This comment has been minimized.

Copy link
@eb4x

eb4x Oct 7, 2022

Suggest a separate flag interfaces_use_nmconnection or something to that effect, for using these new file types, so we can introduce networkmanager with network-scripts, and introduce nmconnections as an experimental feature.

interfaces_pkg_state: present
interfaces_route_tables: []
interfaces_ether_interfaces: []
Expand Down
34 changes: 27 additions & 7 deletions tasks/ethernet_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
- name: Create the network configuration file for ethernet devices
become: true
template:
src: 'ethernet_{{ ansible_facts.os_family }}.j2'
src: 'ethernet_{{ ansible_facts.os_family }}{% if interfaces_use_networkmanager | bool %}_nm{% endif %}.j2'

This comment has been minimized.

Copy link
@eb4x

eb4x Oct 7, 2022

os_family shouldn't have anything to do with NetworkManager key-files. So the template could just be called ethernet_nmconnection.j2 {{ (interfaces_use_nmconnection | bool) | ternary('nmconnection', ansible_facts.os_family) }}

dest: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}/ifcfg-{{ item.device }}'
mode: '0600'
with_items: '{{ interfaces_ether_interfaces }}'
register: ether_result
notify:
Expand All @@ -28,7 +29,10 @@
src: 'route_{{ ansible_facts.os_family }}.j2'
dest: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}/route-{{ item.device }}'
with_items: '{{ interfaces_ether_interfaces }}'
when: item.route is defined and ansible_facts.os_family == 'RedHat'
when:
- item.route is defined
- ansible_facts.os_family == 'RedHat'
- not interfaces_use_networkmanager
register: ether_route_add_result
notify:
- Bounce network devices
Expand All @@ -39,7 +43,11 @@
src: 'route6_{{ ansible_facts.os_family }}.j2'
dest: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}/route6-{{ item.device }}'
with_items: '{{ interfaces_ether_interfaces }}'
when: item.ip6 is defined and item.ip6.route is defined and ansible_facts.os_family == 'RedHat'
when:
- item.ip6 is defined
- item.ip6.route is defined
- ansible_facts.os_family == 'RedHat'
- not interfaces_use_networkmanager
register: ether_route6_add_result
notify:
- Bounce network devices
Expand All @@ -50,7 +58,10 @@
path: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}/route-{{ item.device }}'
state: absent
with_items: '{{ interfaces_ether_interfaces }}'
when: item.route is not defined and ansible_facts.os_family == 'RedHat'
when:
- item.route is not defined
- ansible_facts.os_family == 'RedHat'
- not interfaces_use_networkmanager
register: ether_route_del_result
notify:
- Bounce network devices
Expand All @@ -61,7 +72,10 @@
path: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}/route6-{{ item.device }}'
state: absent
with_items: '{{ interfaces_ether_interfaces }}'
when: item.ip6 is not defined and ansible_facts.os_family == 'RedHat'
when:
- item.ip6 is not defined
- ansible_facts.os_family == 'RedHat'
- not interfaces_use_networkmanager
register: ether_route6_del_result
notify:
- Bounce network devices
Expand All @@ -72,7 +86,10 @@
src: 'rule_{{ ansible_facts.os_family }}.j2'
dest: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}/rule-{{ item.device }}'
with_items: '{{ interfaces_ether_interfaces }}'
when: item.rules is defined and ansible_facts.os_family == 'RedHat'
when:
- item.rules is defined
- ansible_facts.os_family == 'RedHat'
- not interfaces_use_networkmanager
register: ether_rule_add_result
notify:
- Bounce network devices
Expand All @@ -83,7 +100,10 @@
path: '{{ interfaces_net_path[ansible_facts.os_family|lower] }}/rule-{{ item.device }}'
state: absent
with_items: '{{ interfaces_ether_interfaces }}'
when: item.rules is not defined and ansible_facts.os_family == 'RedHat'
when:
- item.rules is not defined
- ansible_facts.os_family == 'RedHat'
- not interfaces_use_networkmanager
register: ether_rule_del_result
notify:
- Bounce network devices
Expand Down
1 change: 1 addition & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- import_tasks: 'route_table_configuration.yml'
tags: configuration
when: not interfaces_use_networkmanager

- import_tasks: 'bond_configuration.yml'
when: interfaces_bond_interfaces is defined
Expand Down
2 changes: 1 addition & 1 deletion tasks/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: RedHat | install current/latest network packages versions
become: true
package:
name: '{{ interfaces_pkgs["redhat"][ansible_facts.distribution_major_version] }}'
name: '{{ interfaces_pkgs["redhat"][ansible_facts.distribution_major_version] }}'
state: '{{ interfaces_pkg_state }}'
tags: package

Expand Down
69 changes: 69 additions & 0 deletions templates/ethernet_RedHat_nm.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# {{ ansible_managed }}

[connection]
id={{ item.device }}
type={{ (item.device is match(vlan_interface_regex)) | ternary('vlan', 'ethernet') }}
interface-name={{ item.device }}
{% if item.onboot is defined %}
autoconnect={{ item.onboot | bool | ternary('yes', 'no') }}
{% endif %}
{% if item.zone is defined %}
zone={{ item.zone }}
{% endif %}

[ethernet]
{% if item.hwaddr is defined %}
mac-address={{ item.hwaddr }}
{% endif %}
{% if item.mtu is defined %}
mtu={{ item.mtu }}
{% endif %}

{% if item.device is match(vlan_interface_regex) %}
[vlan]
parent={{ item.device | regex_replace(vlan_interface_suffix_regex, '') }}
## FIXME(bbezak) - get vlanid from name
id=
{% endif %}

[ipv4]
{% if item.bootproto == 'static' %}
method=manual
{% if item.address is defined %}
{% if item.netmask is defined %}
{% set network_prefix = (item.address ~ item.netmask) | ipaddr('network/prefix') %}
addresses={{ network_prefix }}
{% endif %}
{% endif %}
{% if item.gateway is defined %}
gateway={{ item.gateway }}
{% endif %}
{% if item.dnsnameservers is defined %}
dns={{ item.dnsnameservers|replace(" ",";") ~ ';' }}
{% endif %}
{% if item.dnssearch is defined %}
dns-search={{ item.dnssearch ~ ';' }}
{% endif %}
{% endif %}
{% if item.bootproto == 'dhcp' %}
method=auto
{% endif %}
{# FIXME(bbezak) Defroute has opposite value from never-default setting #}
{% if item.defroute is defined %}
never-default={{ item.defroute | bool | ternary('yes', 'no') }}
{% endif %}
{# TODO(bbezak) Add ethtool-opts #}

{% if item.bootproto == 'static' %}
{% if item.ip6 is defined %}
[ipv6]
method=manual
addresses={{ item.ip6.address ~ '/' ~ item.ip6.prefix }}
{% if item.ip6.gateway is defined %}
gateway={{ item.ip6.gateway }}
{# TODO(bbezak) No IPV6_DEFAULTDEV equivalent in NM?? #}
{% endif %}
{% endif %}
{% endif %}

{# TODO(bbezak) Add routing configuration here for NM #}

0 comments on commit 8aad4f9

Please sign in to comment.