From 9d8c27b3edc40657a02cc13735f06a9aacc634bf Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 4 May 2022 00:40:04 -0400 Subject: [PATCH] split gitlab-job-status.yml into success/failure templates for workflow --- gitlab-job-status-failure.yml | 69 +++++++++++++++++++ ...tatus.yml => gitlab-job-status-success.yml | 0 2 files changed, 69 insertions(+) create mode 100644 gitlab-job-status-failure.yml rename gitlab-job-status.yml => gitlab-job-status-success.yml (100%) diff --git a/gitlab-job-status-failure.yml b/gitlab-job-status-failure.yml new file mode 100644 index 0000000..2cf012f --- /dev/null +++ b/gitlab-job-status-failure.yml @@ -0,0 +1,69 @@ +--- +- name: Create inventory based on extra_vars + hosts: all + gather_facts: no + become: no + + + vars_files: + - vars/defaults.yml + + + vars: + provision_host: "{{ tower_provision_host | default(ansible_play_hosts | join(',')) }}" + + + tasks: + - name: "Create in-memory inventory" + add_host: + name: "{{ item }}" + groups: + - remdiation + delegate_to: localhost + loop: "{{ provision_host.split(',') }}" + + +# =========================================================================== # + + +- name: Post Ansible Job Status to Gitlab + hosts: remdiation + gather_facts: yes + become: no + + + vars_files: + - vars/defaults.yml + + + tasks: + - name : Log fail to Gitlab + delegate_to: localhost + no_log : "{{ __no_log | default('yes') }}" + uri : + url : "{{ gitlab_commit_url }}" + headers : + PRIVATE-TOKEN : "{{ gitlab_pat }}" + method : POST + status_code : 201 + body_format : json + return_content : no + validate_certs : no + body: + id : "{{ gitlab_proj_id }}" + branch : "{{ git_commit_branch }}" + commit_message : "Job {{ lookup('env', 'JOB_ID') | default('N/A', true) }} - {{ inventory_hostname }}; SUCCESS" + author_name : "{{ git_commit_author }}" + author_email : "{{ git_commit_email }}" + actions: + - action : create + file_path : "failed_jobs/{{ lookup('env', 'JOB_ID') | default('', true) }}_\ + {{ inventory_hostname }}_\ + {{ ansible_date_time.iso8601 }}.txt" + content : | + tower_provision_host : {{ inventory_hostname }} + tower_job_id : {{ lookup('env', 'JOB_ID') | default('N/A', true) }} + tower_project_revision : {{ lookup('env', 'PROJECT_REVISION') | default('N/A', true) }} + + +... diff --git a/gitlab-job-status.yml b/gitlab-job-status-success.yml similarity index 100% rename from gitlab-job-status.yml rename to gitlab-job-status-success.yml