mirror of
https://github.com/ansible/awx.git
synced 2026-02-01 09:38:10 -03:30
176 lines
6.3 KiB
YAML
176 lines
6.3 KiB
YAML
---
|
|
# 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)
|
|
# scm_clean: true/false
|
|
# scm_username: username (only for svn/insights)
|
|
# scm_password: password (only for svn/insights)
|
|
# scm_accept_hostkey: true/false (only for git, set automatically)
|
|
# scm_refspec: a refspec to fetch in addition to obtaining version
|
|
# roles_enabled: Value of the global setting to enable roles downloading
|
|
# collections_enabled: Value of the global setting to enable collections downloading
|
|
# roles_destination: Path to save roles from galaxy to
|
|
# collections_destination: Path to save collections from galaxy to
|
|
# awx_version: Current running version of the awx or tower as a string
|
|
# awx_license_type: "open" for AWX; else presume Tower
|
|
|
|
- hosts: localhost
|
|
gather_facts: false
|
|
connection: local
|
|
name: Update source tree if necessary
|
|
tasks:
|
|
|
|
- name: delete project directory before update
|
|
file:
|
|
path: "{{project_path|quote}}"
|
|
state: absent
|
|
tags:
|
|
- delete
|
|
|
|
- block:
|
|
- name: update project using git
|
|
git:
|
|
dest: "{{project_path|quote}}"
|
|
repo: "{{scm_url}}"
|
|
version: "{{scm_branch|quote}}"
|
|
refspec: "{{scm_refspec|default(omit)}}"
|
|
force: "{{scm_clean}}"
|
|
accept_hostkey: "{{scm_accept_hostkey|default(omit)}}"
|
|
register: git_result
|
|
|
|
- name: Set the git repository version
|
|
set_fact:
|
|
scm_version: "{{ git_result['after'] }}"
|
|
when: "'after' in git_result"
|
|
tags:
|
|
- update_git
|
|
|
|
- block:
|
|
- name: include hg tasks
|
|
include_tasks: project_update_hg_tasks.yml
|
|
tags:
|
|
- update_hg
|
|
|
|
- block:
|
|
- name: update project using svn
|
|
subversion:
|
|
dest: "{{project_path|quote}}"
|
|
repo: "{{scm_url|quote}}"
|
|
revision: "{{scm_branch|quote}}"
|
|
force: "{{scm_clean}}"
|
|
username: "{{scm_username|default(omit)}}"
|
|
password: "{{scm_password|default(omit)}}"
|
|
environment:
|
|
LC_ALL: 'en_US.UTF-8'
|
|
register: svn_result
|
|
|
|
- name: Set the svn repository version
|
|
set_fact:
|
|
scm_version: "{{ svn_result['after'] }}"
|
|
when: "'after' in svn_result"
|
|
|
|
- name: parse subversion version string properly
|
|
set_fact:
|
|
scm_version: "{{scm_version|regex_replace('^.*Revision: ([0-9]+).*$', '\\1')}}"
|
|
tags:
|
|
- update_svn
|
|
|
|
- block:
|
|
- name: Ensure the project directory is present
|
|
file:
|
|
dest: "{{project_path|quote}}"
|
|
state: directory
|
|
|
|
- name: Fetch Insights Playbook(s)
|
|
insights:
|
|
insights_url: "{{insights_url}}"
|
|
username: "{{scm_username}}"
|
|
password: "{{scm_password}}"
|
|
project_path: "{{project_path}}"
|
|
awx_license_type: "{{awx_license_type}}"
|
|
awx_version: "{{awx_version}}"
|
|
register: results
|
|
|
|
- name: Save Insights Version
|
|
set_fact:
|
|
scm_version: "{{results.version}}"
|
|
when: results is defined
|
|
tags:
|
|
- update_insights
|
|
|
|
- name: Repository Version
|
|
debug:
|
|
msg: "Repository Version {{ scm_version }}"
|
|
tags:
|
|
- update_git
|
|
- update_hg
|
|
- update_svn
|
|
- update_insights
|
|
|
|
- name: Set content cache location
|
|
set_fact:
|
|
cache_dir: "{{ project_cache }}/{{ scm_version|default(scm_branch) }}"
|
|
tags:
|
|
- install_collections
|
|
- install_roles
|
|
|
|
- block:
|
|
- 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 {{ '--force' if roles_destination is not defined else '' }} -r roles/requirements.yml -p {{ cache_dir }}/requirements_roles {{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
|
|
args:
|
|
chdir: "{{project_path|quote}}"
|
|
register: galaxy_result
|
|
when: doesRequirementsExist.stat.exists
|
|
changed_when: "'was installed successfully' in galaxy_result.stdout"
|
|
environment:
|
|
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_destination is defined and doesRequirementsExist.stat.exists
|
|
|
|
when: roles_enabled|bool
|
|
tags:
|
|
- install_roles
|
|
|
|
- block:
|
|
- 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 {{ '--force' if collections_destination is not defined else '' }} -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
|
|
when: doesCollectionRequirementsExist.stat.exists
|
|
changed_when: "'Installing ' in galaxy_collection_result.stdout"
|
|
environment:
|
|
ANSIBLE_FORCE_COLOR: false
|
|
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: collections_destination is defined and doesCollectionRequirementsExist.stat.exists
|
|
|
|
when:
|
|
- "ansible_version.full is version_compare('2.8', '>=')"
|
|
- collections_enabled|bool
|
|
tags:
|
|
- install_collections
|