Files
tower-tests/inmem-test.yml
2022-02-23 02:37:13 -05:00

140 lines
4.6 KiB
YAML

---
- name: Create inventory based on passed extra_vars
hosts: localhost
gather_facts: no
become: no
vars:
provision_host: "{{ tower_webhook_payload.commits.modified[0] \
| default(tower_provision_host) \
| default('localhost') }}"
tasks:
- name : "Create in-memory inventory for {{ provision_host }}"
add_host :
name : "{{ provision_host }}"
groups :
- remdiation
# =========================================================================== #
- name: Verify file existence and handle errors if needed
hosts: remdiation
gather_facts: yes
become: no
tasks:
- name : Run file test
block :
- name : "Test #1: register file contents"
command :
cmd : cat /tmp/hello-ansible.txt
changed_when : no
register : r_check_file
- name: "Test #2: Launch the `file_removal_test` job template"
no_log : yes
uri :
url : "https://tower2.thezengarden.net/api/v2/job_templates/23/launch/"
force_basic_auth : yes
user : admin
password : redhat
body_format : json
method : POST
status_code : 201
body:
extra_vars:
tower_provision_host": "{{ inventory_hostname }}"
- name: Return job data to originating source
no_log : yes
uri:
url : "https://git.thezengarden.net/api/v4/projects/119/repository/commits"
headers :
PRIVATE-TOKEN : "glpat-DnEVHEjjS_q2_GhyngQV"
method : POST
status_code : 201
body_format : json
return_content : no
validate_certs : no
body:
id : 119
branch : main
commit_message : "{{ inventory_hostname }} - SUCCESS: {{ r_check_file.stdout }}"
author_name : Chris Hammer
author_email : chris.hammer@redhat.com
actions:
- action : create
file_path : "successful_jobs/{{ inventory_hostname }}_{{ ansible_date_time.iso8601 }}.txt"
content : |
tower_provision_host : {{ inventory_hostname }}
tower_provision_rc : {{ r_check_file.rc }}
tower_provision_stdout : {{ r_check_file.stdout }}
rescue:
- name : Exception caught
debug :
msg : "*** EXCEPTION CAUGHT; RUNNING RESCUE TASKS ***"
- name: "Create missing file"
no_log : yes
uri:
url : "https://tower2.thezengarden.net/api/v2/job_templates/22/launch/"
force_basic_auth : yes
user : admin
password : redhat
body_format : json
method : POST
status_code : 201
body:
extra_vars:
tower_provision_host": "{{ inventory_hostname }}"
- name: Return job data to originating source
no_log : yes
uri:
url : "https://git.thezengarden.net/api/v4/projects/119/repository/commits"
headers :
PRIVATE-TOKEN : "glpat-DnEVHEjjS_q2_GhyngQV"
method : POST
status_code : 201
body_format : json
return_content : no
validate_certs : no
body:
id : 119
branch : main
commit_message : "{{ inventory_hostname }} - FAILED: {{ r_check_file.msg }}"
author_name : Chris Hammer
author_email : chris.hammer@redhat.com
actions:
- action : create
file_path : "failed_jobs/{{ inventory_hostname }}_{{ ansible_date_time.iso8601 }}.txt"
content : |
tower_provision_host : {{ inventory_hostname }}
tower_provision_rc : {{ r_check_file.rc }}
tower_provision_stdout : {{ r_check_file.stdout }}
tower_provision_stderr : {{ r_check_file.stderr }}
tower_provision_msg : {{ r_check_file.msg }}
always:
- name : Job complete
debug :
msg :
- "tower_provision_host : {{ inventory_hostname }}"
- "tower_provision_failed : {{ r_check_file.failed }}"
...