89 lines
2.3 KiB
YAML
89 lines
2.3 KiB
YAML
---
|
|
- name: Create inventory based on passed extra_vars
|
|
hosts: localhost
|
|
gather_facts: no
|
|
become: no
|
|
|
|
|
|
vars:
|
|
provision_host: "{{ 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: no
|
|
become: no
|
|
|
|
|
|
vars_files:
|
|
- vars/defaults.yml
|
|
- vars/job_launch_file_creation.yml
|
|
|
|
|
|
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: do something else"
|
|
debug:
|
|
msg: Something, something, and something!
|
|
|
|
|
|
rescue:
|
|
- name: Exception caught
|
|
debug:
|
|
msg:
|
|
- "host : {{ inventory_hostname }}"
|
|
- "rc : {{ r_check_file.rc }}"
|
|
- "stdout : {{ r_check_file.stdout }}"
|
|
- "stderr : {{ r_check_file.stderr }}"
|
|
- "msg : {{ r_check_file.msg }}"
|
|
|
|
|
|
- name: Re-create files as needed
|
|
uri:
|
|
url : "{{ tower_api_host }}/api/v2/job_templates/27/launch/"
|
|
method : POST
|
|
status_code : 201
|
|
force_basic_auth : yes
|
|
url_username : "{{ tower_api_user }}"
|
|
url_password : "{{ tower_api_pass }}"
|
|
body_format : json
|
|
return_content : no
|
|
validate_certs : no
|
|
body:
|
|
extra_vars:
|
|
fail_host : "{{ inventory_hostname }}"
|
|
fail_rc : "{{ r_check_file.rc }}"
|
|
fail_stdout : "{{ r_check_file.stdout }}"
|
|
fail_stderr : "{{ r_check_file.stderr }}"
|
|
fail_msg : "{{ r_check_file.msg }}"
|
|
|
|
|
|
always:
|
|
- name: Job complete
|
|
debug:
|
|
msg:
|
|
- "host : {{ inventory_hostname }}"
|
|
- "failed : {{ r_check_file.failed }}"
|
|
|
|
|
|
...
|