Add combined roles/collection requirements on project sync (#14081)

This commit is contained in:
John Westcott IV
2023-07-05 12:25:44 -04:00
committed by GitHub
parent 0f96d9aca2
commit 3624fe2cac

View File

@@ -189,11 +189,12 @@
connection: local connection: local
name: Install content with ansible-galaxy command if necessary name: Install content with ansible-galaxy command if necessary
vars: vars:
galaxy_task_env: # configure in settings galaxy_task_env: # configured in settings
additional_collections_env: # additional_galaxy_env contains environment variables are used for installing roles and collections and will take precedence over items in galaxy_task_env
# These environment variables are used for installing collections, in addition to galaxy_task_env additional_galaxy_env:
# setting the collections paths silences warnings # These paths control where ansible-galaxy installs collections and roles on top the filesystem
ANSIBLE_COLLECTIONS_PATHS: "{{ projects_root }}/.__awx_cache/{{ local_path }}/stage/requirements_collections" ANSIBLE_COLLECTIONS_PATHS: "{{ projects_root }}/.__awx_cache/{{ local_path }}/stage/requirements_collections"
ANSIBLE_ROLES_PATH: "{{ projects_root }}/.__awx_cache/{{ local_path }}/stage/requirements_roles"
# Put the local tmp directory in same volume as collection destination # Put the local tmp directory in same volume as collection destination
# otherwise, files cannot be moved accross volumes and will cause error # otherwise, files cannot be moved accross volumes and will cause error
ANSIBLE_LOCAL_TEMP: "{{ projects_root }}/.__awx_cache/{{ local_path }}/stage/tmp" ANSIBLE_LOCAL_TEMP: "{{ projects_root }}/.__awx_cache/{{ local_path }}/stage/tmp"
@@ -212,40 +213,50 @@
- name: End play due to disabled content sync - name: End play due to disabled content sync
ansible.builtin.meta: end_play ansible.builtin.meta: end_play
- name: Fetch galaxy roles from requirements.(yml/yaml) - block:
ansible.builtin.command: > - name: Fetch galaxy roles from roles/requirements.(yml/yaml)
ansible-galaxy role install -r {{ item }} ansible.builtin.command:
--roles-path {{ projects_root }}/.__awx_cache/{{ local_path }}/stage/requirements_roles cmd: "ansible-galaxy role install -r {{ item }} {{ verbosity }}"
{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }} register: galaxy_result
args: with_fileglob:
chdir: "{{ project_path | quote }}" - "{{ project_path | quote }}/roles/requirements.yaml"
register: galaxy_result - "{{ project_path | quote }}/roles/requirements.yml"
with_fileglob: changed_when: "'was installed successfully' in galaxy_result.stdout"
- "{{ project_path | quote }}/roles/requirements.yaml" when: roles_enabled | bool
- "{{ project_path | quote }}/roles/requirements.yml" tags:
changed_when: "'was installed successfully' in galaxy_result.stdout" - install_roles
environment: "{{ galaxy_task_env }}"
when: roles_enabled | bool
tags:
- install_roles
- name: Fetch galaxy collections from collections/requirements.(yml/yaml) - name: Fetch galaxy collections from collections/requirements.(yml/yaml)
ansible.builtin.command: > ansible.builtin.command:
ansible-galaxy collection install -r {{ item }} cmd: "ansible-galaxy collection install -r {{ item }} {{ verbosity }}"
--collections-path {{ projects_root }}/.__awx_cache/{{ local_path }}/stage/requirements_collections register: galaxy_collection_result
{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }} with_fileglob:
args: - "{{ project_path | quote }}/collections/requirements.yaml"
chdir: "{{ project_path | quote }}" - "{{ project_path | quote }}/collections/requirements.yml"
register: galaxy_collection_result changed_when: "'Nothing to do.' not in galaxy_collection_result.stdout"
with_fileglob: when:
- "{{ project_path | quote }}/collections/requirements.yaml" - "ansible_version.full is version_compare('2.9', '>=')"
- "{{ project_path | quote }}/collections/requirements.yml" - collections_enabled | bool
- "{{ project_path | quote }}/requirements.yaml" tags:
- "{{ project_path | quote }}/requirements.yml" - install_collections
changed_when: "'Installing ' in galaxy_collection_result.stdout"
environment: "{{ additional_collections_env | combine(galaxy_task_env) }}" - name: Fetch galaxy roles and collections from requirements.(yml/yaml)
when: ansible.builtin.command:
- "ansible_version.full is version_compare('2.9', '>=')" cmd: "ansible-galaxy install -r {{ item }} {{ verbosity }}"
- collections_enabled | bool register: galaxy_combined_result
tags: with_fileglob:
- install_collections - "{{ project_path | quote }}/requirements.yaml"
- "{{ project_path | quote }}/requirements.yml"
changed_when: "'Nothing to do.' not in galaxy_combined_result.stdout"
when:
- "ansible_version.full is version_compare('2.10', '>=')"
- collections_enabled | bool
- roles_enabled | bool
tags:
- install_collections
- install_roles
# We combine our additional_galaxy_env into galaxy_task_env so that our values are preferred over anything a user would set
environment: "{{ galaxy_task_env | combine(additional_galaxy_env) }}"
vars:
verbosity: "{{ (ansible_verbosity) | ternary('-'+'v'*ansible_verbosity, '') }}"