Skip to content

Commit

Permalink
Conditionally copy RPMs locally and to undercloud
Browse files Browse the repository at this point in the history
Before this change, in every execution we copied RPMs from patcher
node to localhost and then to undercloud.

In a case where tester=undercloud we don't need to do it because
if we do, we basically copy RPMs from undercloud to localhost and
back again to the undercloud. This whole process is redundant.

Additionally we are fixing the problem encountered when attempting
to add chosen node to tester group. Previously we faced difficulties
with Ansible<2.8.0, but it caused another issue with functional
testing. After reconsidering the conditions, now all should be fine.

Change-Id: I95922134d638910e712a4fc5cfae3150ef6bca67
  • Loading branch information
sdatko committed May 28, 2020
1 parent 55481b8 commit df36562
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
- name: Set tester node
hosts: localhost
tasks:
# TODO: change groups.tester to groups.tester|first when Ansible will be updated to at least 2.8.0 as there is a bug in ansible < 2.8.0
# where groups.tester|first causing 'name' value to evaluate groups.tester even if groups.undercloud is defined
- name: Add chosen node to tester group
add_host:
name: "{{ install.get('tester', {}).get('node')|default(groups.get('undercloud', {})|first, true)|default(groups.tester, true) }}"
groups: "tester"
- include_role:
name: inventory-update
vars:
inventory_file_name: 'hosts-test'
- when: groups.tester is not defined or groups.tester|length < 1
block:
- name: Add chosen node to tester group
add_host:
name: "{{ install.get('tester', {}).get('node') | default(groups.get('undercloud', [])|first, true) }}"
groups: "tester"
- include_role:
name: inventory-update
vars:
inventory_file_name: 'hosts-test'


- name: add hosts to run the code using ansible-playbook
Expand Down Expand Up @@ -44,6 +44,7 @@
state: directory
suffix: "{{ ansible_date_time.iso8601 }}"
register: tempdir_1
when: "'undercloud' not in groups['tester'][0]"

- name: Copy RPMs
hosts: "{{ install.pattern | default('tester') }}"
Expand All @@ -53,22 +54,24 @@
src: "/patched_rpms/"
dest: "{{ hostvars['localhost']['tempdir_1'].path }}/"
mode: pull
when: "'undercloud' not in groups['tester'][0]"

- name: Update undercloud node
hosts: tester
become: yes
tasks:
- name: Setup repository in /etc/yum.repos.d
template:
src='patched_rpms.j2'
dest='/etc/yum.repos.d/patched_rpms.repo'
src: 'patched_rpms.j2'
dest: '/etc/yum.repos.d/patched_rpms.repo'
tags: patched-rpms-repo

- name: Copy RPMs to the undercloud if created on an another node
synchronize:
src: "{{ hostvars['localhost']['tempdir_1'].path }}/"
dest: "/patched_rpms"
mode: push
when: "'undercloud' not in groups['tester'][0]"

- name: Cleanup
hosts: localhost
Expand All @@ -77,4 +80,6 @@
file:
path: "{{ tempdir_1.path }}"
state: absent
when: tempdir_1.path is defined
when:
- tempdir_1.path is defined
- "'undercloud' not in groups['tester'][0]"

0 comments on commit df36562

Please sign in to comment.