openstack-ansible-tests/get-ansible-role-requiremen...

121 lines
4.5 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.
# Note(odyssey4me):
# This uses a local connection for the lint test which
# never sets up host keys and therefore cannot connect
# to localhost as a remote host.
#
- name: Clone the role ansible-role-requirements
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Check whether zuul-cloner is installed and provide the path to it
shell: |
which zuul-cloner || { [[ -x /usr/zuul-env/bin/zuul-cloner ]] && echo '/usr/zuul-env/bin/zuul-cloner'; }
args:
executable: /bin/bash
changed_when: false
failed_when: false
register: _zuul_cloner_check
- name: Remove target directory if required
shell: |
if [[ ! -d "{{ item.path | default(homedir + '/.ansible/roles') }}/{{ item.name | default(item.src | basename) }}/.git" ]]; then
rm -rf "{{ item.path | default(homedir + '/.ansible/roles') }}/{{ item.name | default(item.src | basename) }}"
fi
args:
executable: /bin/bash
when:
- item.scm == "git" or item.scm is undefined
with_items: "{{ roles }}"
- name: Prepare git clone list
set_fact:
git_roles: >
{%- set filtered_role_list = [] %}
{%- for role in roles %}
{%- if (not role.src | match(".*git.openstack.org.*")) or
(role.name | match("os_previous_.*")) or
(role.name | match("previous_.*")) %}
{%- set _ = filtered_role_list.append(role) %}
{%- endif %}
{%- endfor %}
{{- filtered_role_list -}}
zuul_roles: >
{%- set filtered_role_list = [] %}
{%- for role in roles %}
{%- if (role.src | match(".*git.openstack.org.*")) and (not role.name | match("os_previous_.*")) %}
{%- set role_src_cleaned = role.src | regex_replace('https://git.openstack.org/', '') %}
{%- set _ = filtered_role_list.append(role_src_cleaned) %}
{%- endif %}
{%- endfor %}
{{- filtered_role_list -}}
openstack_repo_list: >
{%- set filtered_repo_list = [] %}
{%- set repo_list = lookup('env', 'ZUUL_CHANGES').split('^') %}
{%- for repo in repo_list %}
{%- set repo_cleaned = repo | regex_replace(':.*$', '') %}
{%- if not repo_cleaned | match("^openstack/openstack-ansible.*") %}
{%- set _ = filtered_repo_list.append(repo_cleaned) %}
{%- endif %}
{%- endfor %}
{{- filtered_repo_list -}}
when:
- _zuul_cloner_check.rc == 0
- name: Clone git repos (with git)
git:
repo: "{{ item.src }}"
dest: "{{ homedir }}/.ansible/roles/{{ item.name | default(item.src | basename) }}"
version: "{{ item.version | default('master') }}"
update: true
force: true
when:
- item.scm == "git" or item.scm is undefined
with_items: "{{ git_roles | default(roles) }}"
- name: Create clone map
copy:
content: |
clonemap:
- name: 'openstack/openstack-ansible-tests'
dest: '{{ lookup("env", "WORKING_DIR") }}/tests/common'
- name: 'openstack/openstack-ansible-(?!tests)(.*)'
dest: '{{ homedir }}/.ansible/roles/\1'
- name: 'openstack/(?!openstack-ansible)(.*)'
dest: '{{ homedir }}/git/openstack/\1'
dest: "{{ homedir }}/.ansible/clonemap.yml"
when:
- _zuul_cloner_check.rc == 0
- name: Clone git repos (with zuul-cloner)
shell: |
{{ _zuul_cloner_check.stdout }} \
-m {{ homedir }}/.ansible/clonemap.yml \
--cache-dir /opt/git \
git://git.openstack.org \
{% for repo in zuul_roles + openstack_repo_list %}
{{ repo }} \
{% endfor %}
when:
- _zuul_cloner_check.rc == 0
vars:
role_file: "{{ toxinidir }}/tests/ansible-role-requirements.yml"
roles: "{{ lookup('file', role_file) | from_yaml }}"