e29a62d87f
Ansible task execution can be a bit slow - so the noop case where we don't end up doing anything can still be costly. Instead, put the when on the loop call, which will apply to each iteration of the loop, not running the loop itself. This way we should only include_tasks if we need to. In order for the utility playbook to keep working, we also run all of the iterations of the loop if gitea_always_update is true. This will make a sync run take a long time but be comprehensive. Change-Id: Ib60c736d46d8253e603de097eb80bc84b3366310
45 lines
1.4 KiB
YAML
45 lines
1.4 KiB
YAML
- name: Get Gerrit project list
|
|
set_fact:
|
|
gerrit_projects: "{{ lookup('file', '/opt/project-config/gerrit/projects.yaml') | from_yaml }}"
|
|
- name: Parse Gerrit org list
|
|
set_fact:
|
|
gerrit_orgs: "{{ gerrit_projects | map(attribute='project') | map('regex_search', '^(.*?)/') | list | unique | select | map('regex_replace', '/', '') | list }}"
|
|
- name: debug
|
|
debug:
|
|
msg: "{{ gerrit_orgs }}"
|
|
- name: Get Gitea org list
|
|
# We assume that all the orgs we are interested in are owned by root
|
|
uri:
|
|
url: "{{ gitea_url }}/api/v1/user/orgs"
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
validate_certs: false
|
|
status_code: 200
|
|
register: gitea_org_list
|
|
- name: Parse Gitea org list
|
|
set_fact:
|
|
gitea_orgs: "{{ gitea_org_list.json | map(attribute='username') | list }}"
|
|
- name: Create orgs
|
|
loop: "{{ gerrit_orgs }}"
|
|
loop_control:
|
|
loop_var: org
|
|
include_tasks: 'setup-org.yaml'
|
|
- name: Get a CSRF token
|
|
uri:
|
|
url: "{{ gitea_url }}/"
|
|
validate_certs: false
|
|
user: root
|
|
password: "{{ gitea_root_password }}"
|
|
force_basic_auth: true
|
|
register: gitea_token
|
|
- name: Parse CSRF taken
|
|
set_fact:
|
|
gitea_token: "{{ gitea_token.cookies._csrf|regex_replace('%3D','=') }}"
|
|
- name: Create repos
|
|
loop: "{{ gerrit_projects }}"
|
|
loop_control:
|
|
loop_var: project
|
|
include_tasks: 'setup-repo.yaml'
|
|
when: gitea_always_update or project.project not in gitea_repos
|