network: Add support for setting static IP on RedHat

This commit is contained in:
Timo Makinen 2020-09-11 16:25:30 +00:00
parent 1a0a8ac1d2
commit f87df3b96d
3 changed files with 56 additions and 0 deletions

View file

@ -3,3 +3,8 @@
- name: restart network - name: restart network
command: /bin/sh /etc/netstart command: /bin/sh /etc/netstart
when: ansible_os_family == "OpenBSD" when: ansible_os_family == "OpenBSD"
- block:
- name: reload network manager connections
command: nmcli c reload
when: ansible_os_family == "RedHat"

View file

@ -1 +1,17 @@
--- ---
- name: get interface uuid
command:
cmd: nmcli -f "DEVICE,UUID,NAME" c show
changed_when: false
check_mode: false
register: interface_uuid
- name: create ethernet interface configurations
template:
src: ifcfg-eth.j2
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.device }}"
mode: 0644
owner: root
group: "{{ ansible_wheel }}"
notify: reload network manager connections
with_items: "{{ network_interfaces }}"

View file

@ -0,0 +1,35 @@
DEVICE="{{ item.device }}"
{% for line in interface_uuid.stdout_lines %}
{% if line.split()[0] == item.device %}
UUID="{{ line.split()[1] }}"
{% elif line.split()[2] == item.device %}
UUID="{{ line.split()[1] }}"
{% endif %}
{% endfor %}
{% if item.mac is defined %}
HWADDR="{{ item.mac }}"
{% elif lookup('vars', 'ansible_' + item.device, default=undefined) is undefined %}
HWADDR="{{ lookup('vars', 'ansible_' + item.device + '["macaddress"]') }}
{% endif %}
ONBOOT=yes
{% if item.proto is not defined or item.proto == 'dhcp' %}
NETBOOT=yes
BOOTPROTO=dhcp
{% elif item.proto == 'static' %}
IPADDR="{{ item.ipaddr }}"
NETMASK="{{ item.netmask }}"
{% if item.gateway is defined %}
GATEWAY="{{ item.gateway }}"
{% endif %}
{% elif proto == 'none' %}
BOOTPROTO=none
{% endif %}
{% if item.ip6addr is defined and item.ip6addr != 'none' %}
IPV6INIT=yes
{% if item.ip6addr != 'auto' %}
IPV6ADDR="{{ item.ip6addr }}"
{% endif %}
{% else %}
IPV6INIT=no
{% endif %}
TYPE=Ethernet