Cache downloaded roles & collections

Populate the cache the first time the job is run for a revision
that needs them, and for future runs for that revision just
copy it into the private directory.

Delete the cache on project deletion.
This commit is contained in:
Bill Nottingham
2020-05-29 15:56:47 -04:00
committed by AlanCoding
parent bedbafe0f9
commit d272ee3521
3 changed files with 33 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
---
# The following variables will be set by the runner of this playbook:
# project_path: PROJECTS_DIR/_local_path_
# project_cache: CACHE_DIR/.__awx_cache/_local_path_
# scm_url: https://server/repo
# insights_url: Insights service URL (from configuration)
# scm_branch: branch/tag/revision (HEAD if unset)
@@ -116,13 +117,17 @@
tasks:
- block:
- name: set content cache location
set_fact:
cache_dir: "{{ project_cache }}/{{ scm_branch }}"
- name: detect requirements.yml
stat:
path: '{{project_path|quote}}/roles/requirements.yml'
register: doesRequirementsExist
- name: fetch galaxy roles from requirements.yml
command: ansible-galaxy role install -r roles/requirements.yml -p {{roles_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
command: ansible-galaxy role install -r roles/requirements.yml -p {{ cache_dir }}/requirements_roles {{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
args:
chdir: "{{project_path|quote}}"
register: galaxy_result
@@ -132,18 +137,27 @@
ANSIBLE_FORCE_COLOR: false
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
- name: populate job directory with needed roles
synchronize:
src: "{{ cache_dir }}/requirements_roles"
dest: "{{ roles_destination }}"
when: roles_enabled|bool
tags:
- install_roles
- block:
- name: set content cache location
set_fact:
cache_dir: "{{ project_cache }}/{{ scm_branch }}"
- name: detect collections/requirements.yml
stat:
path: '{{project_path|quote}}/collections/requirements.yml'
register: doesCollectionRequirementsExist
- name: fetch galaxy collections from collections/requirements.yml
command: ansible-galaxy collection install -r collections/requirements.yml -p {{collections_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
command: ansible-galaxy collection install -r collections/requirements.yml -p {{ cache_dir }}/requirements_collections {{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
args:
chdir: "{{project_path|quote}}"
register: galaxy_collection_result
@@ -151,9 +165,14 @@
changed_when: "'Installing ' in galaxy_collection_result.stdout"
environment:
ANSIBLE_FORCE_COLOR: false
ANSIBLE_COLLECTIONS_PATHS: "{{ collections_destination }}"
ANSIBLE_COLLECTIONS_PATHS: "{{ cache_dir }}/requirements_collections"
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
- name: populate job directory with needed collections
synchronize:
src: "{{ cache_dir }}/requirements_collections"
dest: "{{ collections_destination }}"
when:
- "ansible_version.full is version_compare('2.8', '>=')"
- collections_enabled|bool