xci: roles: configure-network: Wait for connection when configuring the network 35/53335/7
authorMarkos Chandras <mchandras@suse.de>
Thu, 8 Mar 2018 19:51:51 +0000 (19:51 +0000)
committerMarkos Chandras <mchandras@suse.de>
Fri, 9 Mar 2018 14:00:52 +0000 (14:00 +0000)
Ansible some times loses connection with the host after we configure its
network interface. This shouldn't happen since the host is actually up
and running. As a result of which, we need to fire-and-forget the
restart of the network service and then try to reach the SSH port. We
also need to make sure that all required packages are installed.
Finally, we drop the 'ignore_errors' parameter since we really need to
know when the networking configuration has failed.

Change-Id: I366192737b5c4e01964eaf187396eababbdc808e
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/playbooks/roles/configure-network/tasks/main.yml

index adcb866..21f213c 100644 (file)
     path: "/etc/udev/rules.d/99-glean.rules"
     state: absent
 
+- name: Determine required packages
+  set_fact:
+    network_packages:
+      - bridge-utils
+      - "{{ (ansible_pkg_mgr in ['zypper', 'apt']) | ternary('iproute2', 'iproute') }}"
+      - "{{ (ansible_pkg_mgr == 'apt') | ternary('vlan', '') }}"
+      - iptables
+
+- name: Ensure networking packages are present
+  package:
+    name: "{{ network_packages }}"
+    state: present
+
 - block:
     - name: configure modules
       lineinfile:
@@ -31,6 +44,8 @@
         dest: "/etc/network/interfaces"
     - name: restart network service
       shell: "/sbin/ifconfig {{ ansible_default_ipv4.interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a"
+      async: 15
+      poll: 0
   when: ansible_os_family | lower == "debian"
 
 - block:
         dest: "/etc/sysconfig/network/ifroute-{{ item.name }}"
       with_items:
         - { name: "br-vlan", gateway: "192.168.122.1", route: "default" }
-
     - name: restart network service
-      shell: "/usr/sbin/wicked ifreload all"
+      service:
+        name: network
+        state: restarted
+      async: 15
+      poll: 0
   when: ansible_os_family | lower == "suse"
 
 - block:
       lineinfile:
         path: "/etc/sysconfig/network-scripts/ifcfg-br-vlan"
         line: "GATEWAY=192.168.122.1"
-    - name: Restart networking
-      command: "systemctl restart network"
-    - name: wait for the server to come back
-      wait_for_connection:
+    - name: restart network service
+      service:
+        name: network
+        state: restarted
+      async: 15
+      poll: 0
   when: ansible_os_family | lower == "redhat"
+
+- local_action:
+    module: wait_for
+    host: "{{ ansible_host }}"
+    delay: 15
+    state: started
+    port: 22
+    connect_timeout: 10
+    timeout: 180