net iface config templating and decouple resolvconf from NM
This commit is contained in:
parent
2b98197025
commit
bd13e567f2
3 changed files with 73 additions and 0 deletions
|
@ -201,3 +201,15 @@
|
||||||
|
|
||||||
- name: restart mirrorlist-server
|
- name: restart mirrorlist-server
|
||||||
service: name=mirrorlist-server state=restarted
|
service: name=mirrorlist-server state=restarted
|
||||||
|
|
||||||
|
- name: restart NetworkManager
|
||||||
|
service: name=NetworkManager state=restarted
|
||||||
|
|
||||||
|
- name: reload NetworkManager
|
||||||
|
command: nmcli c reload
|
||||||
|
|
||||||
|
- name: apply interface-changes
|
||||||
|
command: nmcli con up {{ item.split()[1] }}
|
||||||
|
with_items:
|
||||||
|
- "{{ if_uuid.stdout_lines }}"
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,42 @@
|
||||||
- resolvconf
|
- resolvconf
|
||||||
- base
|
- base
|
||||||
|
|
||||||
|
- name: disable resolv.conf control from NM
|
||||||
|
ini_file: dest=/etc/NetworkManager/NetworkManager.conf section=main option=dns value=none
|
||||||
|
notify:
|
||||||
|
- restart NetworkManager
|
||||||
|
when: ansible_distribution_major_version|int >=7
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
- resolvconf
|
||||||
|
- base
|
||||||
|
|
||||||
|
- name: get interface uuid
|
||||||
|
shell: nmcli -f "DEVICE,UUID" c show --active | grep -E '^eth|^br'
|
||||||
|
register: if_uuid
|
||||||
|
changed_when: false
|
||||||
|
failed_when: 'if_uuid.stdout == ""'
|
||||||
|
always_run: yes
|
||||||
|
when: ansible_distribution_major_version|int >=7
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
- ifcfg
|
||||||
|
- base
|
||||||
|
|
||||||
|
- name: copy ifcfg files - non virthost
|
||||||
|
template: src=ifcfg.j2 dest=/etc/sysconfig/network-scripts/ifcfg-{{item}} mode=644
|
||||||
|
with_items:
|
||||||
|
- "{{ ansible_interfaces }}"
|
||||||
|
notify:
|
||||||
|
- restart NetworkManager
|
||||||
|
- reload NetworkManager
|
||||||
|
- apply interface-changes
|
||||||
|
when: (virthost is not defined) and (not item.startswith('tun')) and (hostvars[inventory_hostname]['ansible_' + item]['type'] == 'ether') and (ansible_distribution_major_version|int >=7) and hostvars[inventory_hostname]['ansible_' + item]['active']
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
- ifcfg
|
||||||
|
- base
|
||||||
|
|
||||||
- name: global default packages to install (yum)
|
- name: global default packages to install (yum)
|
||||||
yum: state=present name={{ item }}
|
yum: state=present name={{ item }}
|
||||||
with_items:
|
with_items:
|
||||||
|
|
25
roles/base/templates/ifcfg.j2
Normal file
25
roles/base/templates/ifcfg.j2
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
NAME="{{item}}"
|
||||||
|
BOOTPROTO="none"
|
||||||
|
{% if item == "eth0" %}
|
||||||
|
GATEWAY="{{gw}}"
|
||||||
|
{% endif %}
|
||||||
|
HWADDR="{{ hostvars[inventory_hostname]['ansible_' + item]['macaddress']|upper }}"
|
||||||
|
IPADDR="{{ hostvars[inventory_hostname][item + '_ip'] }}"
|
||||||
|
NETMASK="{{ hostvars[inventory_hostname][item + '_nm'] }}"
|
||||||
|
ONBOOT="yes"
|
||||||
|
TYPE="Ethernet"
|
||||||
|
DEVICE="{{item}}"
|
||||||
|
{% for line in if_uuid.stdout_lines %}
|
||||||
|
{% if line.split()[0] == item %}
|
||||||
|
UUID="{{ line.split()[1] }}"
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if has_ipv6 is defined %}
|
||||||
|
IPV6INIT=yes
|
||||||
|
IPV6ADDR_SECONDARIES="{{ hostvars[inventory_hostname][item + '_ipv6'] }}"
|
||||||
|
IPV6_ROUTER=no
|
||||||
|
IPV6_AUTOCONF=no
|
||||||
|
IPV6_DEFAULTDEV={{item}}
|
||||||
|
IPV6_DEFAULTGW={{ hostvars[inventory_hostname][item + '_ipv6_gw'] }}
|
||||||
|
IPV6_MTU=1280
|
||||||
|
{% endif %}
|
Loading…
Add table
Add a link
Reference in a new issue