network: Add support for setting static IP on RedHat
This commit is contained in:
parent
1a0a8ac1d2
commit
f87df3b96d
3 changed files with 56 additions and 0 deletions
|
@ -3,3 +3,8 @@
|
|||
- name: restart network
|
||||
command: /bin/sh /etc/netstart
|
||||
when: ansible_os_family == "OpenBSD"
|
||||
|
||||
- block:
|
||||
- name: reload network manager connections
|
||||
command: nmcli c reload
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
|
|
@ -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 }}"
|
||||
|
|
35
roles/network/templates/ifcfg-eth.j2
Normal file
35
roles/network/templates/ifcfg-eth.j2
Normal 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
|
Loading…
Add table
Reference in a new issue