summaryrefslogtreecommitdiffstats
path: root/xci/playbooks
diff options
context:
space:
mode:
authorMarkos Chandras <mchandras@suse.de>2018-03-28 16:10:28 +0100
committerMarkos Chandras <mchandras@suse.de>2018-03-28 22:05:21 +0100
commit396ea65c98f71580a2e789c7d93c8d8611878b64 (patch)
tree9ec5127a61b523deb058fa982d61b251b747c02c /xci/playbooks
parent25ec0a542c5948b4ec515138ddb339fa12234a4b (diff)
xci: bootstrap-host: Make active network interface consistent
When we run XCI for the first time, Ansible picks the first active interface as the default one. However, after we configure all the XCI bridges etc, and we try to run this role again, Ansible may have changed its mind about what interface is active and it could default to one of the bridges. This forces the role to redo the network configuration but this time the bridges are being attached to bridges so everything goes terribly wrong after that. The way to solve this would be to add a local fact about what interface should be considered as the 'real' default one so subsequent calls to this role to not destroy the network. This also drops the task which removed the network configuration files on SUSE platforms since Ansible is smart enough to not touch them if they are configured properly. Change-Id: Ic0525e934b1934a40d69e6cf977615ab9b3dac6d Signed-off-by: Markos Chandras <mchandras@suse.de>
Diffstat (limited to 'xci/playbooks')
-rw-r--r--xci/playbooks/roles/bootstrap-host/handlers/main.yml12
-rw-r--r--xci/playbooks/roles/bootstrap-host/tasks/network.yml59
2 files changed, 50 insertions, 21 deletions
diff --git a/xci/playbooks/roles/bootstrap-host/handlers/main.yml b/xci/playbooks/roles/bootstrap-host/handlers/main.yml
new file mode 100644
index 00000000..b9103233
--- /dev/null
+++ b/xci/playbooks/roles/bootstrap-host/handlers/main.yml
@@ -0,0 +1,12 @@
+---
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2018 SUSE Linux GmbH and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+- name: Reload facts
+ setup:
+ filter: ansible_local
diff --git a/xci/playbooks/roles/bootstrap-host/tasks/network.yml b/xci/playbooks/roles/bootstrap-host/tasks/network.yml
index ea9060e6..92e9195e 100644
--- a/xci/playbooks/roles/bootstrap-host/tasks/network.yml
+++ b/xci/playbooks/roles/bootstrap-host/tasks/network.yml
@@ -25,6 +25,31 @@
name: "{{ network_packages }}"
state: present
+- name: Ensure local facts directory exists
+ file:
+ path: "/etc/ansible/facts.d"
+ state: directory
+
+# NOTE(hwoarang) We have to check all levels of the local fact before we add it
+# otherwise Ansible will fail.
+- name: Record initial active interface
+ ini_file:
+ create: yes
+ section: network
+ state: present
+ option: xci_interface
+ value: "{{ ansible_default_ipv4.interface }}"
+ path: "/etc/ansible/facts.d/xci.fact"
+ when: ansible_local is not defined
+ or (ansible_local is defined and ansible_local.xci is not defined)
+ or (ansible_local is defined and ansible_local.xci is defined and ansible_local.xci.network is not defined)
+ or (ansible_local is defined and ansible_local.xci is defined and ansible_local.xci.network is defined and ansible_local.xci.network.xci_interface is not defined)
+ notify:
+ - Reload facts
+
+- name: Run handlers
+ meta: flush_handlers
+
- block:
- name: configure modules
lineinfile:
@@ -48,33 +73,25 @@
src: "{{ ansible_os_family | lower }}/{{ ansible_hostname }}.interface.j2"
dest: "/etc/network/interfaces"
- name: restart network service
- shell: "/sbin/ifconfig {{ ansible_default_ipv4.interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a"
+ shell: "/sbin/ifconfig {{ ansible_local.xci.network.xci_interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a"
async: 15
poll: 0
when: ansible_os_family | lower == "debian"
- block:
- - name: Remove existing network configuration
- file:
- path: "/etc/sysconfig/network/{{ item }}"
- state: absent
- with_items:
- - "ifcfg-eth0"
- - "ifroute-eth0"
-
- name: Configure networking on SUSE
template:
src: "{{ ansible_os_family | lower }}/suse.interface.j2"
dest: "/etc/sysconfig/network/ifcfg-{{ item.name }}"
with_items:
- - { 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: "{{ ansible_local.xci.network.xci_interface }}" }
+ - { name: "{{ ansible_local.xci.network.xci_interface }}.10", vlan_id: 10 }
+ - { name: "{{ ansible_local.xci.network.xci_interface }}.30", vlan_id: 30 }
+ - { name: "{{ ansible_local.xci.network.xci_interface }}.20", vlan_id: 20 }
+ - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", ip: "{{ host_info[inventory_hostname].MGMT_IP }}/22" }
+ - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", ip: "{{ host_info[inventory_hostname].VXLAN_IP }}/22" }
+ - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", ip: "{{ host_info[inventory_hostname].VLAN_IP }}/24" }
+ - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}/22" }
- name: Add postup/postdown scripts on SUSE
copy:
@@ -102,10 +119,10 @@
src: "{{ ansible_os_family | lower }}/interface.ifcfg.j2"
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}"
with_items:
- - { 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: "{{ ansible_local.xci.network.xci_interface }}" , bridge: "br-vlan" }
+ - { name: "{{ ansible_local.xci.network.xci_interface }}.10", bridge: "br-mgmt" , vlan_id: 10 }
+ - { name: "{{ ansible_local.xci.network.xci_interface }}.20", bridge: "br-storage", vlan_id: 20 }
+ - { name: "{{ ansible_local.xci.network.xci_interface }}.30", bridge: "br-vxlan" , vlan_id: 30 }
- name: Configure networking on CentOS for bridges
template:
src: "{{ ansible_os_family | lower }}/bridge.ifcfg.j2"