diff --git a/handlers/restart_services.yml b/handlers/restart_services.yml index 621dc9a1e4..75236e13b5 100644 --- a/handlers/restart_services.yml +++ b/handlers/restart_services.yml @@ -201,3 +201,15 @@ - name: restart mirrorlist-server 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 }}" + diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index 9f48d28cb0..bc176a3ff5 100644 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -19,6 +19,42 @@ - resolvconf - 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) yum: state=present name={{ item }} with_items: diff --git a/roles/base/templates/ifcfg.j2 b/roles/base/templates/ifcfg.j2 new file mode 100644 index 0000000000..11ba66c839 --- /dev/null +++ b/roles/base/templates/ifcfg.j2 @@ -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 %}