98d1b58b94
This patch clears up an Ansible warning that is thrown each time the `get-ansible-role-requirements.yml` playbook runs. The playbook has a variable called `roles`, but that's a reserved variable name. The patch changes the variable name to `required_roles` to avoid the warning. Closes-Bug: 1735781 Change-Id: I91e5505408e53271155ac80e2997595ddf3b8781
99 lines
3.6 KiB
YAML
99 lines
3.6 KiB
YAML
---
|
|
# 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: Clone the role ansible-role-requirements
|
|
hosts: localhost
|
|
connection: local
|
|
user: root
|
|
tasks:
|
|
- name: Remove target directory if required
|
|
shell: |
|
|
if [[ ! -d "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}/.git" ]]; then
|
|
rm -rf "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}"
|
|
fi
|
|
args:
|
|
executable: /bin/bash
|
|
when:
|
|
- item.scm == "git" or item.scm is undefined
|
|
with_items: "{{ required_roles }}"
|
|
|
|
- name: Ensure the default roles directory exists
|
|
file:
|
|
path: "{{ role_path_default }}"
|
|
state: directory
|
|
|
|
- name: Use Zuul provided sources in Zuul environment
|
|
block:
|
|
- name: Check the Zuul src dir for cloned roles
|
|
stat:
|
|
path: "/home/zuul/src/{{ item.src.split('/')[-3:] | join('/') }}"
|
|
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('/') }}"
|
|
dest: "{{ item.item.path | default(role_path_default) }}/{{ item.item.name | default(item.item.src | basename) }}"
|
|
state: link
|
|
owner: root
|
|
group: root
|
|
with_items: "{{ zuul_roles.results
|
|
| selectattr('stat.exists')
|
|
| list }}"
|
|
when:
|
|
- "lookup('env', 'ZUUL_PROJECT') != ''"
|
|
|
|
- name: Clone git repos (with git)
|
|
git:
|
|
repo: "{{ item.src }}"
|
|
dest: "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}"
|
|
version: "{{ item.version | default('master') }}"
|
|
refspec: "{{ item.refspec | default(omit) }}"
|
|
depth: "{{ item.depth | default('10') }}"
|
|
update: true
|
|
force: true
|
|
when:
|
|
- item.scm == "git" or item.scm is undefined
|
|
with_items: "{{ (zuul_roles.results | default([]) |
|
|
selectattr('stat', 'defined') |
|
|
rejectattr('stat.exists') |
|
|
map(attribute='item') | list)
|
|
| default(roles, True) }}"
|
|
register: git_clone
|
|
retries: "{{ git_clone_retries }}"
|
|
delay: "{{ git_clone_retry_delay }}"
|
|
async: 1800
|
|
poll: 0
|
|
|
|
- name: Wait for git clones to complete
|
|
async_status:
|
|
jid: "{{ item['ansible_job_id'] }}"
|
|
register: _git_jobs
|
|
until: _git_jobs['finished'] | bool
|
|
delay: 5
|
|
retries: 360
|
|
with_items: "{{ git_clone['results'] }}"
|
|
when:
|
|
- item['ansible_job_id'] is defined
|
|
|
|
vars:
|
|
ansible_python_interpreter: "/usr/bin/python"
|
|
required_roles: "{{ lookup('file', role_file) | from_yaml }}"
|
|
role_file: '../ansible-role-requirements.yml'
|
|
role_path_default: '/etc/ansible/roles'
|
|
git_clone_retries: 2
|
|
git_clone_retry_delay: 5
|