forked from openstack/openstack-ansible-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-ansible-role-requirements.yml
142 lines (130 loc) · 5.7 KB
/
get-ansible-role-requirements.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
# 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
become: no
gather_facts: false
tasks:
- name: Set name for role under testing
set_fact:
role_name: "{{ lookup('env', 'ROLE_NAME') | default('') }}"
- name: Remove target role directories if they are not git repositories
shell: |
EXIT_CODE=0
{% for role in osa_roles %}
{% if role['scm'] == "git" or role['scm'] is undefined %}
ROLE_REPO_PATH="{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ role['name'] | default(role['src'] | basename) }}"
if [[ -e ${ROLE_REPO_PATH} ]] && [[ ! -d "${ROLE_REPO_PATH}/.git" ]]; then
echo "${ROLE_REPO_PATH} is not a git repo, deleting..."
rm -rf "${ROLE_REPO_PATH}"
EXIT_CODE=2
fi
{% endif %}
{% endfor %}
exit ${EXIT_CODE}
args:
executable: /bin/bash
register: existing_dir_cleanup
changed_when: existing_dir_cleanup.rc == 2
failed_when: existing_dir_cleanup.rc not in [0,2]
- name: Create the ansible role directory
file:
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}"
state: directory
- name: Check whether we are in openstack-ci
stat:
path: /etc/ci/mirror_info.sh
register: _openstack_ci
- name: Clone git repos (outside openstack-ci)
when: not _openstack_ci.stat.exists
block:
- name: Clone git repos
git:
repo: "{{ item['src'] }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ 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
with_items: "{{ osa_roles }}"
retries: "{{ git_clone_retries | default(3) }}"
delay: "{{ git_clone_retry_delay | default(5) }}"
when:
- item['scm'] == "git" or item['scm'] is undefined
- role_name == '' or item['name'] != role_name
- name: Clone git repos (inside openstack-ci)
when: _openstack_ci.stat.exists
block:
- name: Find repositories already cloned by zuul
command: "find {{ zuul_git_src_dir }} -type d -maxdepth 2"
register: zuul_src_folder
- name: Simplify the given src repository list
set_fact:
zuul_src_repo_list: >
{%- set filtered_repo_list = [] %}
{%- for folder_path in zuul_src_folder['stdout_lines'] %}
{%- if folder_path | match("^" ~ zuul_git_src_dir ~ "/openstack/(openstack-ansible-|ansible-role-){1}(?!tests).*") %}
{%- set repo_cleaned = folder_path | regex_replace('^' ~ zuul_git_src_dir ~ '/', '') %}
{%- set _ = filtered_repo_list.append(repo_cleaned) %}
{%- endif %}
{%- endfor %}
{{- filtered_repo_list -}}
- name: Prepare git clone list
set_fact:
git_roles: >
{%- set filtered_role_list = [] %}
{%- for role in osa_roles %}
{%- if (role['name'] | match('os_previous_.*')) or
(role['name'] | match('previous_.*')) or
(role['src'] | regex_replace('https://(?:git.openstack.org|opendev.org)/', '') not in zuul_src_repo_list) %}
{%- set _ = filtered_role_list.append(role) %}
{%- endif %}
{%- endfor %}
{{- filtered_role_list -}}
- name: Link the zuul provided roles
file:
src: "{{ zuul_git_src_dir }}/{{ item }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ item | regex_replace('openstack/(openstack-ansible-|ansible-role-)', '') }}"
state: link
force: yes
with_items: "{{ zuul_src_repo_list }}"
# Do not link the role we are testing
when: role_name == '' or not item | search(role_name)
- name: Clone the remaining git repos
git:
repo: "{{ item['src'] }}"
dest: "{{ lookup('env', 'ANSIBLE_ROLE_DEP_DIR') }}/{{ 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
with_items: "{{ git_roles }}"
retries: "{{ git_clone_retries | default(3) }}"
delay: "{{ git_clone_retry_delay | default(5) }}"
when:
- item['scm'] == "git" or item['scm'] is undefined
vars:
homedir: "{{ lookup('env', 'TESTING_HOME') }}"
role_file: "{{ lookup('env', 'ANSIBLE_ROLE_REQUIREMENTS_PATH') }}"
osa_roles: "{{ lookup('file', role_file) | from_yaml }}"
zuul_git_src_dir: "/home/zuul/src/opendev.org"