diff --git a/tasks/main.yml b/tasks/main.yml index b8b827a..c03b8d7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -22,12 +22,28 @@ dest=/etc/network/interfaces state=present insertafter=EOF - when: ansible_os_family == "Debian" + when: ansible_os_family == "Debian" and (oldskool is not defined or not oldskool) + +- name: Make sure the include line is not there in interfaces file (oldskool) + lineinfile: > + regexp="^source\ \/etc\/network\/interfaces.d\/\*" + dest=/etc/network/interfaces + state=absent + when: ansible_os_family == "Debian" and oldskool is defined and oldskool - name: Create the directory for interface cfg files file: path=/etc/network/interfaces.d state=directory when: ansible_os_family == "Debian" +- name: Check whether the original interfaces file was already backed up + stat: path=/etc/network/interfaces.d/00interfaces.orig + register: interfacesbackup + when: ansible_os_family == "Debian" and oldskool is defined and oldskool + +- name: Backup the original interfaces file + command: cp /etc/network/interfaces /etc/network/interfaces.d/00interfaces.orig + when: ansible_os_family == "Debian" and not interfacesbackup.stat.exists and oldskool is defined and oldskool + - name: Create the network configuration file for ethernet devices template: src=ethernet_{{ ansible_os_family }}.j2 dest={{ net_path }}/ifcfg-{{ item.device }} with_items: network_ether_interfaces @@ -39,9 +55,6 @@ with_items: network_ether_interfaces when: network_ether_interfaces is defined and item.route is defined and ansible_os_family == 'RedHat' -- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }} - with_items: ether_result.results - when: ether_result is defined and item.changed - name: Create the network configuration file for bridge devices template: src=bridge_{{ ansible_os_family }}.j2 dest={{ net_path }}/ifcfg-{{ item.device }} @@ -54,9 +67,6 @@ with_items: network_bridge_interfaces when: network_bridge_interfaces is defined and item.route is defined and ansible_os_family == 'RedHat' -- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }} - with_items: bridge_result.results - when: bridge_result is defined and item.changed - name: Create the network configuration file for port on the bridge devices template: src=bridge_port_{{ ansible_os_family }}.j2 dest={{ net_path }}/ifcfg-{{ item.1 }} @@ -66,9 +76,6 @@ when: network_bridge_interfaces is defined register: bridge_port_result -- shell: ifdown {{ item.item.1 }}; ifup {{ item.item.1 }} - with_items: bridge_port_result.results - when: bridge_port_result is defined and item.changed - name: Create the network configuration file for bond devices template: src=bond_{{ ansible_os_family }}.j2 dest={{ net_path }}/ifcfg-{{ item.device }} @@ -85,9 +92,6 @@ with_items: network_bond_interfaces when: network_bond_interfaces is defined and item.route is defined and ansible_os_family == 'RedHat' -- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }} - with_items: bond_result.results - when: bond_result is defined and item.changed - name: Create the network configuration file for slave in the bond devices template: src=bond_slave_{{ ansible_os_family }}.j2 dest={{ net_path }}/ifcfg-{{ item.1 }} @@ -97,6 +101,29 @@ when: network_bond_interfaces is defined register: bond_port_result + +- assemble: src=/etc/network/interfaces.d dest=/etc/network/interfaces mode=0644 + when: ansible_os_family == "Debian" and oldskool is defined and oldskool + +- file: path=/etc/network/interfaces.d/00interfaces.orig state=absent + when: ansible_os_family == "Debian" and (oldskool is not defined or not oldskool) + +- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }} + with_items: ether_result.results + when: ether_result is defined and item.changed + +- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }} + with_items: bridge_result.results + when: bridge_result is defined and item.changed + +- shell: ifdown {{ item.item.1 }}; ifup {{ item.item.1 }} + with_items: bridge_port_result.results + when: bridge_port_result is defined and item.changed + +- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }} + with_items: bond_result.results + when: bond_result is defined and item.changed + - shell: ifdown {{ item.item.1 }}; ifup {{ item.item.1 }} with_items: bond_port_result.results when: bond_port_result is defined and item.changed