From bd1c450b2216d3cf534237f7e005b2e4574a3ed6 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Wed, 28 Mar 2018 15:59:17 -0700 Subject: [PATCH] use command to gather host distribution, kernel version facts disable ansible gather_facts as it takes too long (7 minutes) to get those facts Signed-off-by: Guohan Lu --- ansible/roles/vm_set/tasks/main.yml | 26 +++++++++++++++++------- ansible/testbed_add_vm_topology.yml | 1 + ansible/testbed_remove_vm_topology.yml | 1 + ansible/testbed_renumber_vm_topology.yml | 1 + ansible/testbed_start_VMs.yml | 1 + ansible/testbed_stop_VMs.yml | 1 + 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ansible/roles/vm_set/tasks/main.yml b/ansible/roles/vm_set/tasks/main.yml index 8bff5b8b370..80054e27177 100644 --- a/ansible/roles/vm_set/tasks/main.yml +++ b/ansible/roles/vm_set/tasks/main.yml @@ -15,17 +15,29 @@ # Need latest ubuntu 4.10 kernel to fix a openvswitch bug # https://bugs.launchpad.net/ubuntu/+source/kernel-package/+bug/1685742 +- name: get host distribution + shell: grep ^NAME /etc/os-release | awk -F '=' '{print $2}' | tr -d '"' + register: host_distribution + +- name: get host distribution version + shell: grep ^VERSION_ID /etc/os-release | awk -F '=' '{print $2}' | tr -d '"' + register: host_distribution_version + +- name: get host kernel version + shell: uname -r + register: host_kernel + - name: Check if kernel upgrade needed set_fact: kernel_upgrade_needed: true when: - - ansible_distribution == "Ubuntu" - - ansible_distribution_version == "17.04" - - ansible_kernel.find('4.10.0') != -1 - - "{{ ansible_kernel | regex_replace('4.10.0-([0-9]+)-.*', '\\1') | int < 25 }}" + - host_distribution.stdout == "Ubuntu" + - host_distribution_version.stdout == "17.04" + - host_kernel.find('4.10.0') != -1 + - "{{ host_kernel | regex_replace('4.10.0-([0-9]+)-.*', '\\1') | int < 25 }}" - block: - - debug: msg="{{ ansible_kernel }}" + - debug: msg="{{ host_kernel }}" - name: Upgrade kernel package apt: pkg={{ item }} state=latest @@ -44,14 +56,14 @@ repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu zesty stable state: present become: yes - when: ansible_distribution_version == "17.04" + when: host_distribution_version == "17.04" - name: Add docker repository for 16.04 apt_repository: repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable state: present become: yes - when: ansible_distribution_version == "16.04" + when: host_distribution_version == "16.04" - name: Install necessary packages apt: pkg={{ item }} update_cache=yes cache_valid_time=86400 diff --git a/ansible/testbed_add_vm_topology.yml b/ansible/testbed_add_vm_topology.yml index 000360ee75e..e99a71bf405 100644 --- a/ansible/testbed_add_vm_topology.yml +++ b/ansible/testbed_add_vm_topology.yml @@ -28,6 +28,7 @@ # -e ptf_imagename=docker-ptf - name of a docker-image which will be used for the ptf docker container - hosts: servers:&vm_host + gather_facts: no vars_files: - vars/docker_registry.yml pre_tasks: diff --git a/ansible/testbed_remove_vm_topology.yml b/ansible/testbed_remove_vm_topology.yml index b17d5b8412f..7b68b163e68 100644 --- a/ansible/testbed_remove_vm_topology.yml +++ b/ansible/testbed_remove_vm_topology.yml @@ -15,6 +15,7 @@ # -e ptf_imagename=docker-ptf - name of a docker-image which will be used for the ptf docker container - hosts: servers:&vm_host + gather_facts: no vars_files: - vars/docker_registry.yml pre_tasks: diff --git a/ansible/testbed_renumber_vm_topology.yml b/ansible/testbed_renumber_vm_topology.yml index 727eddfef8c..879b250cae5 100644 --- a/ansible/testbed_renumber_vm_topology.yml +++ b/ansible/testbed_renumber_vm_topology.yml @@ -14,6 +14,7 @@ # -e ptf_imagename=docker-ptf - name of a docker-image which will be used for the ptf docker container - hosts: servers:&vm_host + gatheer_facts: no vars_files: - vars/docker_registry.yml pre_tasks: diff --git a/ansible/testbed_start_VMs.yml b/ansible/testbed_start_VMs.yml index 73afc1506b0..88ede17283e 100644 --- a/ansible/testbed_start_VMs.yml +++ b/ansible/testbed_start_VMs.yml @@ -16,6 +16,7 @@ # - hosts: servers:&vm_host + gather_facts: no vars_files: - vars/azure_storage.yml tasks: diff --git a/ansible/testbed_stop_VMs.yml b/ansible/testbed_stop_VMs.yml index bc413fd55ea..9e4d850fbd3 100644 --- a/ansible/testbed_stop_VMs.yml +++ b/ansible/testbed_stop_VMs.yml @@ -11,5 +11,6 @@ # - hosts: servers:&vm_host + gather_facts: no roles: - { role: vm_set, action: 'stop' }