From 6720cd9bda2bd11da2e2661cf777483f767225d0 Mon Sep 17 00:00:00 2001 From: Philip Douglass Date: Tue, 30 Jul 2019 22:34:14 -0400 Subject: [PATCH] Add block to download and unpack a remote archive Signed-off-by: Philip Douglass --- awx/playbooks/project_update.yml | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/awx/playbooks/project_update.yml b/awx/playbooks/project_update.yml index e572496497..22478f9f0c 100644 --- a/awx/playbooks/project_update.yml +++ b/awx/playbooks/project_update.yml @@ -101,6 +101,65 @@ tags: - update_insights + - block: + - name: Ensure the project directory is present + file: + dest: "{{ project_path|quote }}" + state: directory + + - name: Get archive from url + get_url: + url: "{{ scm_url|quote }}" + dest: "{{ project_path|quote }}" + url_username: "{{ scm_username|default(omit) }}" + url_password: "{{ scm_password|default(omit) }}" + force_basic_auth: yes + force: "{{ scm_clean }}" + register: get_url_result + + - name: Unpack archive + unarchive: + src: "{{ get_url_result.dest }}" + dest: "{{ project_path|quote }}" + keep_newer: "{{ not scm_clean }}" + list_files: yes + register: unarchived + + - set_fact: + archive_root_dirs: "{{ archive_root_dirs |default([]) |union(item.split('/')[0:1]) }}" + loop: "{{ unarchived.files }}" + + - block: + - name: Delete unarchived single root directory + file: + dest: "{{ project_path|quote }}/{{ archive_root_dirs[0] }}" + state: absent + + - name: Link single root directory to project directory + file: + src: "{{ project_path|quote }}" + dest: "{{ project_path|quote }}/{{ archive_root_dirs[0] }}" + state: link + + - name: Unpack archive + unarchive: + src: "{{ get_url_result.dest }}" + dest: "{{ project_path|quote }}" + keep_newer: "{{ not scm_clean }}" + + - name: Delete link + file: + dest: "{{ project_path|quote }}/{{ archive_root_dirs[0] }}" + state: absent + when: archive_root_dirs |length == 1 + + - name: Set scm_version to archive sha1 checksum + set_fact: + scm_version: "{{ get_url_result.checksum_src }}" + + tags: + - update_archive + - name: Repository Version debug: msg: "Repository Version {{ scm_version }}" @@ -109,6 +168,7 @@ - update_hg - update_svn - update_insights + - update_archive - hosts: localhost gather_facts: false