mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 18:50:04 -03:30
153 lines
4.6 KiB
YAML
153 lines
4.6 KiB
YAML
---
|
|
|
|
# The following variables will be set by the runner of this playbook:
|
|
# project_path: PROJECTS_DIR/_local_path_
|
|
# scm_type: git|hg|svn
|
|
# scm_url: https://server/repo
|
|
# scm_branch: HEAD
|
|
# scm_clean: true/false
|
|
# scm_delete_on_update: true/false
|
|
# scm_username: username (only for svn)
|
|
# scm_password: password (only for svn)
|
|
# scm_accept_hostkey: true/false (only for git)
|
|
# scm_revision: current revision in tower
|
|
|
|
- hosts: all
|
|
connection: local
|
|
gather_facts: false
|
|
tasks:
|
|
|
|
- name: delete project directory before update
|
|
file:
|
|
path: "{{project_path|quote}}"
|
|
state: absent
|
|
when: scm_delete_on_update|default('')
|
|
|
|
- block:
|
|
- name: update project using git and accept hostkey
|
|
git:
|
|
dest: "{{project_path|quote}}"
|
|
repo: "{{scm_url}}"
|
|
version: "{{scm_branch|quote}}"
|
|
force: "{{scm_clean}}"
|
|
accept_hostkey: "{{scm_accept_hostkey}}"
|
|
when: scm_accept_hostkey is defined
|
|
register: scm_result
|
|
|
|
- name: Set the git repository version
|
|
set_fact:
|
|
scm_version: "{{ scm_result['after'] }}"
|
|
when: "'after' in scm_result"
|
|
|
|
- name: update project using git
|
|
git:
|
|
dest: "{{project_path|quote}}"
|
|
repo: "{{scm_url}}"
|
|
version: "{{scm_branch|quote}}"
|
|
force: "{{scm_clean}}"
|
|
when: scm_accept_hostkey is not defined
|
|
register: scm_result
|
|
|
|
- name: Set the git repository version
|
|
set_fact:
|
|
scm_version: "{{ scm_result['after'] }}"
|
|
when: "'after' in scm_result"
|
|
when: scm_type == 'git'
|
|
|
|
- block:
|
|
- name: update project using hg
|
|
hg:
|
|
dest: "{{project_path|quote}}"
|
|
repo: "{{scm_url|quote}}"
|
|
revision: "{{scm_branch|quote}}"
|
|
force: "{{scm_clean}}"
|
|
register: scm_result
|
|
|
|
- name: Set the hg repository version
|
|
set_fact:
|
|
scm_version: "{{ scm_result['after'] }}"
|
|
when: "'after' in scm_result"
|
|
|
|
- name: parse hg version string properly
|
|
set_fact:
|
|
scm_version: "{{scm_version|regex_replace('^([A-Za-z0-9]+).*$', '\\1')}}"
|
|
when: scm_type == 'hg'
|
|
|
|
- block:
|
|
- name: update project using svn
|
|
subversion:
|
|
dest: "{{project_path|quote}}"
|
|
repo: "{{scm_url|quote}}"
|
|
revision: "{{scm_branch|quote}}"
|
|
force: "{{scm_clean}}"
|
|
when: not scm_username|default('')
|
|
register: scm_result
|
|
|
|
- name: Set the svn repository version
|
|
set_fact:
|
|
scm_version: "{{ scm_result['after'] }}"
|
|
when: "'after' in scm_result"
|
|
|
|
- name: update project using svn with auth
|
|
subversion:
|
|
dest: "{{project_path|quote}}"
|
|
repo: "{{scm_url|quote}}"
|
|
revision: "{{scm_branch|quote}}"
|
|
force: "{{scm_clean}}"
|
|
username: "{{scm_username|quote}}"
|
|
password: "{{scm_password|quote}}"
|
|
when: scm_username|default('')
|
|
register: scm_result
|
|
|
|
- name: Set the svn repository version
|
|
set_fact:
|
|
scm_version: "{{ scm_result['after'] }}"
|
|
when: "'after' in scm_result"
|
|
|
|
- name: parse subversion version string properly
|
|
set_fact:
|
|
scm_version: "{{scm_version|regex_replace('^.*Revision: ([0-9]+).*$', '\\1')}}"
|
|
when: scm_type == '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}}"
|
|
register: results
|
|
|
|
- name: Save Insights Version
|
|
set_fact:
|
|
scm_version: "{{results.version}}"
|
|
when: results is defined
|
|
when: scm_type == 'insights'
|
|
|
|
|
|
- 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 install -r requirements.yml -p {{project_path|quote}}/roles/ --force
|
|
args:
|
|
chdir: "{{project_path|quote}}/roles"
|
|
when: doesRequirementsExist.stat.exists
|
|
when: scm_full_checkout|bool
|
|
|
|
- name: Repository Version
|
|
debug: msg="Repository Version {{ scm_version }}"
|
|
when: scm_version is defined
|
|
|
|
- name: Write Repository Version
|
|
copy:
|
|
dest: "{{ scm_revision_output }}"
|
|
content: "{{ scm_version }}"
|
|
when: scm_version is defined and scm_revision_output is defined |