Use ZUUL_SRC_PATH to pass the path to Zuul git sources

To make get-ansible-role-requirements usable for 3rd party Zuul based
CI, which may have test nodes that do not conform to the previously
hard-coded /home/zuul home path for Zuul workers, we need to make
this Zuul sources path dynamic based on the home directory of the
Zuul worker user.

However, we cannot rely on {{ ansible_user_dir }} inside
get-ansible-role-requirements.yml, since it uses become: yes. This
means ansible_user_dir will be /root, rather than the Zuul user's
home directory.

The solution is to pass the ZUUL_SRC_PATH that Zuul is operating
with into the OSA test job environment, and use this environment var
inside our role cloning playbook to locate the Zuul sources.

Change-Id: Id71c6502741285e7b83d40be8006e82c9960b7ff
This commit is contained in:
Logan V 2018-07-12 10:08:35 -05:00
parent df5f9738df
commit 47eddb946b
2 changed files with 16 additions and 6 deletions

View File

@ -36,16 +36,22 @@
- name: Use Zuul provided sources in Zuul environment
block:
- name: Set Zuul sources path
set_fact:
zuul_src_path: "{{ lookup('env', 'ZUUL_SRC_PATH') }}"
- name: Check the Zuul src dir for cloned roles
stat:
path: "/home/zuul/src/{{ item.src.split('/')[-3:] | join('/') }}"
path: "{{ zuul_src_path }}/{{ item.src.split('/')[-3:] | join('/') }}"
get_attributes: no
get_checksum: no
get_mime: no
register: zuul_roles
when:
- item.scm == "git" or item.scm is undefined
with_items: "{{ required_roles }}"
- name: Link the Zuul provided roles
file:
src: "/home/zuul/src/{{ item.item.src.split('/')[-3:] | join('/') }}"
src: "{{ zuul_src_path }}/{{ item.item.src.split('/')[-3:] | join('/') }}"
dest: "{{ item.item.path | default(role_path_default) }}/{{ item.item.name | default(item.item.src | basename) }}"
state: link
owner: root
@ -54,7 +60,7 @@
| selectattr('stat.exists')
| list }}"
when:
- "lookup('env', 'ZUUL_PROJECT') != ''"
- "lookup('env', 'ZUUL_SRC_PATH') != ''"
- name: Clone git repos (with git)
git:

View File

@ -1,5 +1,9 @@
- hosts: all
tasks:
- name: Set the Zuul sources path
set_fact:
zuul_src_path: "{{ ansible_user_dir }}/src"
- name: Set current test repo (cross-repo)
set_fact:
current_test_repo: "git.openstack.org/{{ osa_test_repo }}"
@ -19,7 +23,7 @@
args:
chdir: "src/{{ current_test_repo }}"
environment:
# ZUUL_PROJECT is used by tests/get-ansible-role-requirements to
# determine when CI provided repos should be used.
ZUUL_PROJECT: "{{ zuul.project.short_name }}"
# ZUUL_SRC_PATH is used by tests/get-ansible-role-requirements to
# where the CI provided git sources were cloned.
ZUUL_SRC_PATH: "{{ zuul_src_path }}"
ANSIBLE_PACKAGE: "{{ ansible_package | default('') }}"