xci: roles: configure-network: Determine host NIC from Ansible facts 81/52181/4
authorMarkos Chandras <mchandras@suse.de>
Thu, 15 Feb 2018 08:57:47 +0000 (08:57 +0000)
committerMarkos Chandras <mchandras@suse.de>
Wed, 21 Feb 2018 17:37:05 +0000 (17:37 +0000)
Hardcoding the interface as a variable is very fragile since it varies
from host to host. We could use the Ansible facts to find out the
interface name and then use that to configure all the VLANs and
networking.

Change-Id: Ie7e2409d638625b9bede23b6c1fe33dc36f81840
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/installer/kubespray/playbooks/group_vars/all
xci/playbooks/roles/configure-network/tasks/main.yml
xci/playbooks/roles/configure-network/templates/debian/compute00.interface.j2
xci/playbooks/roles/configure-network/templates/debian/controller00.interface.j2
xci/playbooks/roles/configure-network/templates/debian/opnfv.interface.j2
xci/playbooks/roles/configure-network/templates/redhat/interface.ifcfg.j2
xci/playbooks/roles/configure-network/templates/suse/suse.interface.j2
xci/var/Debian.yml
xci/var/RedHat.yml
xci/var/Suse.yml

index 06dccb6..d2c36bf 100644 (file)
@@ -10,7 +10,7 @@ keepalived_sync_groups:
     instances:
       - external
 
-haproxy_keepalived_external_interface: "{{ interface }}"
+haproxy_keepalived_external_interface: "{{ ansible_default_ipv4.interface }}"
 haproxy_keepalived_authentication_password: 'keepalived'
 keepalived_instances:
   external:
index 65abaa4..adcb866 100644 (file)
@@ -30,7 +30,7 @@
         src: "{{ ansible_os_family | lower }}/{{ ansible_hostname }}.interface.j2"
         dest: "/etc/network/interfaces"
     - name: restart network service
-      shell: "/sbin/ifconfig {{ interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a"
+      shell: "/sbin/ifconfig {{ ansible_default_ipv4.interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a"
   when: ansible_os_family | lower == "debian"
 
 - block:
         src: "{{ ansible_os_family | lower }}/suse.interface.j2"
         dest: "/etc/sysconfig/network/ifcfg-{{ item.name }}"
       with_items:
-        - { name: "{{ interface }}" }
-        - { name: "{{ interface }}.10", vlan_id: 10 }
-        - { name: "{{ interface }}.30", vlan_id: 30 }
-        - { name: "{{ interface }}.20", vlan_id: 20 }
-        - { name: "br-mgmt", bridge_ports: "{{ interface }}.10", ip: "{{ host_info[inventory_hostname].MGMT_IP }}/22" }
-        - { name: "br-vxlan", bridge_ports: "{{ interface }}.30", ip: "{{ host_info[inventory_hostname].VXLAN_IP }}/22" }
-        - { name: "br-vlan", bridge_ports: "{{ interface }}", ip: "{{ host_info[inventory_hostname].VLAN_IP }}/24" }
-        - { name: "br-storage", bridge_ports: "{{ interface }}.20", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}/22" }
+        - { name: "{{ ansible_default_ipv4.interface }}" }
+        - { name: "{{ ansible_default_ipv4.interface }}.10", vlan_id: 10 }
+        - { name: "{{ ansible_default_ipv4.interface }}.30", vlan_id: 30 }
+        - { name: "{{ ansible_default_ipv4.interface }}.20", vlan_id: 20 }
+        - { name: "br-mgmt", bridge_ports: "{{ ansible_default_ipv4.interface }}.10", ip: "{{ host_info[inventory_hostname].MGMT_IP }}/22" }
+        - { name: "br-vxlan", bridge_ports: "{{ ansible_default_ipv4.interface }}.30", ip: "{{ host_info[inventory_hostname].VXLAN_IP }}/22" }
+        - { name: "br-vlan", bridge_ports: "{{ ansible_default_ipv4.interface }}", ip: "{{ host_info[inventory_hostname].VLAN_IP }}/24" }
+        - { name: "br-storage", bridge_ports: "{{ ansible_default_ipv4.interface }}.20", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}/22" }
 
     - name: Add postup/postdown scripts on SUSE
       copy:
         src: "{{ ansible_os_family | lower }}/interface.ifcfg.j2"
         dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}"
       with_items:
-        - { name: "{{ interface }}"   , bridge: "br-vlan"                 }
-        - { name: "{{ interface }}.10", bridge: "br-mgmt"   , vlan_id: 10 }
-        - { name: "{{ interface }}.20", bridge: "br-storage", vlan_id: 20 }
-        - { name: "{{ interface }}.30", bridge: "br-vxlan"  , vlan_id: 30 }
+        - { name: "{{ ansible_default_ipv4.interface }}"   , bridge: "br-vlan"                 }
+        - { name: "{{ ansible_default_ipv4.interface }}.10", bridge: "br-mgmt"   , vlan_id: 10 }
+        - { name: "{{ ansible_default_ipv4.interface }}.20", bridge: "br-storage", vlan_id: 20 }
+        - { name: "{{ ansible_default_ipv4.interface }}.30", bridge: "br-vxlan"  , vlan_id: 30 }
     - name: Configure networking on CentOS for bridges
       template:
         src: "{{ ansible_os_family | lower }}/bridge.ifcfg.j2"
index 6d6a383..2da12f2 100644 (file)
@@ -5,23 +5,23 @@ auto lo
 iface lo inet loopback
 
 # Physical interface
-auto {{ interface }}
-iface {{ interface }} inet manual
+auto {{ ansible_default_ipv4.interface }}
+iface {{ ansible_default_ipv4.interface }} inet manual
 
 # Container/Host management VLAN interface
-auto {{ interface }}.10
-iface {{ interface }}.10 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.10
+iface {{ ansible_default_ipv4.interface }}.10 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # OpenStack Networking VXLAN (tunnel/overlay) VLAN interface
-auto {{ interface }}.30
-iface {{ interface }}.30 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.30
+iface {{ ansible_default_ipv4.interface }}.30 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # Storage network VLAN interface
-auto {{ interface }}.20
-iface {{ interface }}.20 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.20
+iface {{ ansible_default_ipv4.interface }}.20 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # Container/Host management bridge
 auto br-mgmt
@@ -29,7 +29,7 @@ iface br-mgmt inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.10
+    bridge_ports {{ ansible_default_ipv4.interface }}.10
     address {{host_info[inventory_hostname].MGMT_IP}}
     netmask 255.255.252.0
 
@@ -39,7 +39,7 @@ iface br-vxlan inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.30
+    bridge_ports {{ ansible_default_ipv4.interface }}.30
     address {{host_info[inventory_hostname].VXLAN_IP}}
     netmask 255.255.252.0
 
@@ -49,7 +49,7 @@ iface br-vlan inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}
+    bridge_ports {{ ansible_default_ipv4.interface }}
     address {{host_info[inventory_hostname].VLAN_IP}}
     netmask 255.255.255.0
     gateway 192.168.122.1
@@ -70,6 +70,6 @@ iface br-storage inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.20
+    bridge_ports {{ ansible_default_ipv4.interface }}.20
     address {{host_info[inventory_hostname].STORAGE_IP}}
     netmask 255.255.252.0
index b461b20..c540f66 100644 (file)
@@ -5,23 +5,23 @@ auto lo
 iface lo inet loopback
 
 # Physical interface
-auto {{ interface }}
-iface {{ interface }} inet manual
+auto {{ ansible_default_ipv4.interface }}
+iface {{ ansible_default_ipv4.interface }} inet manual
 
 # Container/Host management VLAN interface
-auto {{ interface }}.10
-iface {{ interface }}.10 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.10
+iface {{ ansible_default_ipv4.interface }}.10 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # OpenStack Networking VXLAN (tunnel/overlay) VLAN interface
-auto {{ interface }}.30
-iface {{ interface }}.30 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.30
+iface {{ ansible_default_ipv4.interface }}.30 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # Storage network VLAN interface (optional)
-auto {{ interface }}.20
-iface {{ interface }}.20 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.20
+iface {{ ansible_default_ipv4.interface }}.20 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # Container/Host management bridge
 auto br-mgmt
@@ -29,7 +29,7 @@ iface br-mgmt inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.10
+    bridge_ports {{ ansible_default_ipv4.interface }}.10
     address {{host_info[inventory_hostname].MGMT_IP}}
     netmask 255.255.252.0
 
@@ -39,7 +39,7 @@ iface br-vxlan inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.30
+    bridge_ports {{ ansible_default_ipv4.interface }}.30
     address {{host_info[inventory_hostname].VXLAN_IP}}
     netmask 255.255.252.0
 
@@ -49,7 +49,7 @@ iface br-vlan inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}
+    bridge_ports {{ ansible_default_ipv4.interface }}
     address {{host_info[inventory_hostname].VLAN_IP}}
     netmask 255.255.255.0
     gateway 192.168.122.1
@@ -69,6 +69,6 @@ iface br-storage inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.20
+    bridge_ports {{ ansible_default_ipv4.interface }}.20
     address {{host_info[inventory_hostname].STORAGE_IP}}
     netmask 255.255.252.0
index 4282641..03f81db 100644 (file)
@@ -5,23 +5,23 @@ auto lo
 iface lo inet loopback
 
 # Physical interface
-auto {{ interface }}
-iface {{ interface }} inet manual
+auto {{ ansible_default_ipv4.interface }}
+iface {{ ansible_default_ipv4.interface }} inet manual
 
 # Container/Host management VLAN interface
-auto {{ interface }}.10
-iface {{ interface }}.10 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.10
+iface {{ ansible_default_ipv4.interface }}.10 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # OpenStack Networking VXLAN (tunnel/overlay) VLAN interface
-auto {{ interface }}.30
-iface {{ interface }}.30 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.30
+iface {{ ansible_default_ipv4.interface }}.30 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # Storage network VLAN interface (optional)
-auto {{ interface }}.20
-iface {{ interface }}.20 inet manual
-    vlan-raw-device {{ interface }}
+auto {{ ansible_default_ipv4.interface }}.20
+iface {{ ansible_default_ipv4.interface }}.20 inet manual
+    vlan-raw-device {{ ansible_default_ipv4.interface }}
 
 # Container/Host management bridge
 auto br-mgmt
@@ -29,7 +29,7 @@ iface br-mgmt inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.10
+    bridge_ports {{ ansible_default_ipv4.interface }}.10
     address {{host_info[inventory_hostname].MGMT_IP}}
     netmask 255.255.252.0
 
@@ -39,7 +39,7 @@ iface br-vxlan inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.30
+    bridge_ports {{ ansible_default_ipv4.interface }}.30
     address {{ host_info[inventory_hostname].VXLAN_IP }}
     netmask 255.255.252.0
 
@@ -49,7 +49,7 @@ iface br-vlan inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}
+    bridge_ports {{ ansible_default_ipv4.interface }}
     address {{host_info[inventory_hostname].VLAN_IP}}
     netmask 255.255.255.0
     gateway 192.168.122.1
@@ -61,6 +61,6 @@ iface br-storage inet static
     bridge_stp off
     bridge_waitport 0
     bridge_fd 0
-    bridge_ports {{ interface }}.20
+    bridge_ports {{ ansible_default_ipv4.interface }}.20
     address {{host_info[inventory_hostname].STORAGE_IP}}
     netmask 255.255.252.0
index b0dea0f..a97ad0c 100644 (file)
@@ -4,7 +4,7 @@ ONBOOT=yes
 BOOTPROTO=none
 {% if item.vlan_id is defined %}
 VLAN=yes
-ETHERDEVICE={{ interface }}
+ETHERDEVICE={{ ansible_default_ipv4.interface }}
 VLAN_ID={{ item.vlan_id }}
 {% endif %}
 BRIDGE={{ item.bridge }}
index ffa418d..27b01eb 100644 (file)
@@ -1,7 +1,7 @@
 STARTMODE='auto'
 BOOTPROTO='static'
 {% if item.vlan_id is defined %}
-ETHERDEVICE={{ interface }}
+ETHERDEVICE={{ ansible_default_ipv4.interface }}
 VLAN_ID={{ item.vlan_id }}
 {% endif %}
 {% if item.bridge_ports is defined %}
index bd07473..ad3621b 100644 (file)
@@ -8,7 +8,6 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 # this is the interface the VM nodes are connected to libvirt network "default"
-interface: "ens3"
 python_crypto_package_name: python-crypto
 docker_package_name: docker.io
 docker_service_name: docker
index 814d060..8ea2e15 100644 (file)
@@ -8,7 +8,6 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 # this is placeholder and left blank intentionally to complete later on
-interface: "ens3"
 python_crypto_package_name: python-crypto
 docker_package_name: docker
 docker_service_name: docker
index a041e18..5066def 100644 (file)
@@ -8,7 +8,6 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 # this is the interface the VM nodes are connected to libvirt network "default"
-interface: "eth0"
 python_crypto_package_name: python-pycrypto
 docker_package_name: docker
 docker_service_name: docker