From 2266ba91ec48d71b7532f9fecdeed401e95a1fa3 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Fri, 26 Aug 2016 13:48:05 -0500 Subject: [PATCH] Create common task for nodepool specific tasks Change-Id: Ib8b76b539e27872fec1b2208595c07ce3dfb360e Signed-off-by: Kevin Carter --- common-tasks/test-set-nodepool-vars.yml | 48 +++++++++++++++++++++++++ setting-nodepool-variables.yml | 16 +-------- test-prepare-host.yml | 33 +++++------------ 3 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 common-tasks/test-set-nodepool-vars.yml diff --git a/common-tasks/test-set-nodepool-vars.yml b/common-tasks/test-set-nodepool-vars.yml new file mode 100644 index 00000000..fdccd002 --- /dev/null +++ b/common-tasks/test-set-nodepool-vars.yml @@ -0,0 +1,48 @@ +--- +# Copyright 2016, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Check if this is an OpenStack-CI nodepool instance + stat: + path: /etc/nodepool/provider + register: nodepool + delegate_to: localhost + +- name: Determine the existing Ubuntu repo URL + shell: 'awk "/^deb .*ubuntu\/? {{ ansible_distribution_release }} main/ {print \$2; exit}" /etc/apt/sources.list' + register: ubuntu_repo_url + changed_when: false + when: + - ansible_pkg_mgr == 'apt' + delegate_to: localhost + +- name: Set apt repo facts based on discovered information + set_fact: + lxc_container_template_main_apt_repo: "{{ ubuntu_repo_url.stdout }}" + lxc_container_template_security_apt_rep: "{{ ubuntu_repo_url.stdout }}" + when: + - ansible_os_family == 'Debian' + +- name: Set the files to copy into the container cache for OpenStack-CI instances + set_fact: + lxc_container_cache_files: + - { src: '/etc/pip.conf', dest: '/etc/pip.conf' } + when: + - nodepool.stat.exists | bool + +- name: Set Ubuntu Cloud Archive repo URL based on discovered information + set_fact: + uca_apt_repo_url: "{{ ubuntu_repo_url.stdout | netorigin }}/ubuntu-cloud-archive" + when: + - ansible_pkg_mgr == 'apt' diff --git a/setting-nodepool-variables.yml b/setting-nodepool-variables.yml index c6be5801..199db54f 100644 --- a/setting-nodepool-variables.yml +++ b/setting-nodepool-variables.yml @@ -17,18 +17,4 @@ hosts: all gather_facts: false tasks: - - name: Check if this is an OpenStack-CI nodepool instance - stat: - path: /etc/nodepool/provider - register: nodepool - delegate_to: localhost - - name: Determine the existing Ubuntu repo URL (only on OpenStack-CI) - shell: 'awk "/^deb .*ubuntu\/? {{ ansible_distribution_release }} main/ {print \$2; exit}" /etc/apt/sources.list' - register: ubuntu_repo_url - changed_when: false - when: ansible_pkg_mgr == 'apt' and nodepool.stat.exists == True - delegate_to: localhost - - name: Set Ubuntu Cloud Archive repo URL based on discovered information - set_fact: - uca_apt_repo_url: "{{ ubuntu_repo_url.stdout | netorigin }}/ubuntu-cloud-archive" - when: ansible_pkg_mgr == 'apt' and nodepool.stat.exists == True + - include: "common-tasks/test-set-nodepool-vars.yml" diff --git a/test-prepare-host.yml b/test-prepare-host.yml index dda44d64..a1cb69ae 100644 --- a/test-prepare-host.yml +++ b/test-prepare-host.yml @@ -17,6 +17,7 @@ hosts: localhost pre_tasks: - include: "common-tasks/test-force-package-cache-update.yml" + - include: "common-tasks/test-set-nodepool-vars.yml" - name: Clear iptables rules shell: "{{ playbook_dir }}/iptables-clear.sh" - name: Ensure roots new public ssh key is in authorized_keys @@ -26,26 +27,6 @@ manage_dir: no - set_fact: lxc_container_ssh_key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}" - - name: Check if this is an OpenStack-CI nodepool instance - stat: - path: /etc/nodepool/provider - register: nodepool - - name: Set the files to copy into the container cache for OpenStack-CI instances - set_fact: - lxc_container_cache_files: - - { src: '/etc/pip.conf', dest: '/etc/pip.conf' } - when: nodepool.stat.exists | bool - - name: Determine the existing Ubuntu repo configuration - when: ansible_os_family == 'Debian' - shell: 'awk "/^deb .*ubuntu\/? {{ ansible_distribution_release }} main/ {print \$2; exit}" /etc/apt/sources.list' - register: ubuntu_repo - changed_when: false - - name: Set apt repo facts based on discovered information - when: ansible_os_family == 'Debian' - set_fact: - lxc_container_template_main_apt_repo: "{{ ubuntu_repo.stdout }}" - lxc_container_template_security_apt_rep: "{{ ubuntu_repo.stdout }}" - uca_apt_repo_url: "{{ ubuntu_repo_url.stdout | netorigin }}/ubuntu-cloud-archive" roles: - role: "lxc_hosts" post_tasks: @@ -61,6 +42,8 @@ src: "{{ network_conf_filename }}" dest: /etc/network/interfaces.d/test_interfaces.cfg register: network_interfaces + when: + - network_conf_filename is defined - name: Ensure our interfaces.d configuration files are loaded automatically lineinfile: @@ -71,12 +54,16 @@ - name: Shut down the network interfaces command: "ifdown {{ item }}" - when: network_interfaces | changed + when: + - network_interfaces | changed + - network_conf_filename is defined with_items: bridges - name: Start the network interfaces command: "ifup {{ item }}" - when: network_interfaces | changed + when: + - network_interfaces | changed + - network_conf_filename is defined with_items: bridges - name: Add iptables rule to ensure ssh checksum is correct @@ -97,7 +84,5 @@ - name: Add iptables rules for lxc natting command: /usr/local/bin/lxc-system-manage iptables-create - roles: - - role: "lxc_hosts" vars_files: - test-vars.yml