From cb1b86c1144a05696281ced598867cfaf7ce1e76 Mon Sep 17 00:00:00 2001 From: Hans van den Bogert Date: Thu, 17 Mar 2016 17:11:56 +0100 Subject: [PATCH 1/2] Add "manual" option as bootproto This option is useful when the interface is needed to come "up", but does not necessarily needs an IP. --- templates/ethernet_Debian.j2 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/ethernet_Debian.j2 b/templates/ethernet_Debian.j2 index fba82e1..b306fe2 100644 --- a/templates/ethernet_Debian.j2 +++ b/templates/ethernet_Debian.j2 @@ -17,6 +17,11 @@ auto {{ item.device }} iface {{ item.device }} inet dhcp {% endif %} +{% if item.bootproto == 'manual' %} +auto {{ item.device }} +iface {{ item.device }} inet manual +{% endif %} + {% if item.route is defined %} {% for i in item.route %} up route add -net {{ i.network }} netmask {{ i.netmask }} gw {{ i.gateway }} dev {{ item.device }} From 81c906d7e5142ab355ab56749515a1e5054a23cc Mon Sep 17 00:00:00 2001 From: Hans van den Bogert Date: Sat, 11 Jun 2016 16:34:04 +0200 Subject: [PATCH 2/2] Adhere to ansible 2.x for variable expansion after with_items: --- tasks/main.yml | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index b8b827a..c1f7bdd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,13 +5,13 @@ - name: Install the required packages in Redhat derivatives yum: name={{ item }} state=installed - with_items: network_pkgs + with_items: "{{ network_pkgs }}" when: ansible_os_family == 'RedHat' - name: Install the required packages in Debian derivatives apt: name={{ item }} state=installed update_cache=yes - with_items: network_pkgs - environment: env + with_items: "{{ network_pkgs }}" + environment: "{{ env }}" when: ansible_os_family == 'Debian' @@ -30,49 +30,49 @@ - 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 + with_items: "{{ network_ether_interfaces }}" when: network_ether_interfaces is defined register: ether_result - name: Write configuration files for rhel route configuration - template: src=route_{{ ansible_os_family }}.j2 dest={{ net_path }}/route-{{ item.device }} - with_items: network_ether_interfaces + template: src=route_{{ ansible_os_family }}.j2 dest={{ net_path }}/route-{{ item.device }} + 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 + 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 }} - with_items: network_bridge_interfaces - when: network_bridge_interfaces is defined + with_items: "{{ network_bridge_interfaces }}" + when: network_bridge_interfaces is defined register: bridge_result - name: Write configuration files for rhel route configuration - template: src=route_{{ ansible_os_family }}.j2 dest={{ net_path }}/route-{{ item.device }} - with_items: network_bridge_interfaces + template: src=route_{{ ansible_os_family }}.j2 dest={{ net_path }}/route-{{ item.device }} + 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 + 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 }} - with_subelements: - - network_bridge_interfaces + with_subelements: + - "{{ network_bridge_interfaces }}" - ports - when: network_bridge_interfaces is defined + 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 + 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 }} - with_items: network_bond_interfaces + with_items: "{{ network_bond_interfaces }}" when: network_bond_interfaces is defined register: bond_result @@ -81,26 +81,26 @@ when: bond_result|changed - name: Write configuration files for route configuration - template: src=route_{{ ansible_os_family }}.j2 dest={{ net_path }}/route-{{ item.device }} - with_items: network_bond_interfaces + template: src=route_{{ ansible_os_family }}.j2 dest={{ net_path }}/route-{{ item.device }} + 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 + 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 }} - with_subelements: - - network_bond_interfaces + with_subelements: + - "{{ network_bond_interfaces }}" - bond_slaves when: network_bond_interfaces is defined register: bond_port_result - shell: ifdown {{ item.item.1 }}; ifup {{ item.item.1 }} - with_items: bond_port_result.results + with_items: "{{ bond_port_result.results }}" when: bond_port_result is defined and item.changed - shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }} - with_items: bond_result.results + with_items: "{{ bond_result.results }}" when: bond_result is defined and item.changed and ansible_os_family == 'RedHat'