-------- - Added new method to call the webhook via handler - Added inventory_hostname to webhook calls to see who is doing what - Updated messages for better readability - Added comment markers for clarity
115 lines
3.1 KiB
YAML
115 lines
3.1 KiB
YAML
- name: Increment counter
|
|
ansible.builtin.set_fact:
|
|
rcount: "{{ 1 if rcount is undefined else rcount | int + 1 }}"
|
|
|
|
|
|
########################
|
|
# FAILURE BLOCK: START #
|
|
########################
|
|
- name: Abort run and notify if retries exceed defined limits
|
|
when: rcount|int >= fail_count
|
|
block:
|
|
- name: Show rcount and num_retries
|
|
ansible.builtin.debug:
|
|
msg: "{{ inventory_hostname }}: Failed on retry {{ rcount }} \
|
|
with a max of {{ num_retries }}"
|
|
|
|
- name: Log failure to API
|
|
ansible.builtin.uri:
|
|
url : "{{ webhook }}"
|
|
headers:
|
|
Authorization : "Token {{ webhook_key }}"
|
|
Content-type : 'application/json'
|
|
method : POST
|
|
status_code : 200
|
|
validate_certs : false
|
|
return_content : false
|
|
body_format : json
|
|
body : |
|
|
"{{ inventory_hostname }}": "Job FAIL."
|
|
|
|
- name: End condition met.
|
|
ansible.builtin.fail:
|
|
msg: "Bye"
|
|
|
|
######################
|
|
# FAILURE BLOCK: END #
|
|
######################
|
|
|
|
|
|
###########################
|
|
# SUCCESSFUL BLOCK: START #
|
|
###########################
|
|
- name: We were successful
|
|
when: rcount|int == num_retries
|
|
block:
|
|
- name: Show rcount and num_retries
|
|
ansible.builtin.debug:
|
|
msg: "{{ inventory_hostname }}: Success on retry {{ rcount }} with \
|
|
a max of {{ num_retries }}"
|
|
|
|
- name: Log success to API
|
|
ansible.builtin.uri:
|
|
url : "{{ webhook }}"
|
|
headers:
|
|
Authorization : "Token {{ webhook_key }}"
|
|
Content-type : 'application/json'
|
|
method : POST
|
|
status_code : 200
|
|
validate_certs : false
|
|
return_content : false
|
|
body_format : json
|
|
body : |
|
|
"{{ inventory_hostname }}": "Job success."
|
|
|
|
- name: Flush handlers.
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
- name: End condition met.
|
|
ansible.builtin.meta: end_play
|
|
|
|
#########################
|
|
# SUCCESSFUL BLOCK: END #
|
|
#########################
|
|
|
|
|
|
########################
|
|
# GENERAL TASKS: START #
|
|
########################
|
|
- name: Run a series of test commands
|
|
ansible.builtin.command: "{{ item }}"
|
|
loop : "{{ check_commands }}"
|
|
register : r_check_commands
|
|
notify : Bob
|
|
|
|
- name: Current status
|
|
ansible.builtin.debug:
|
|
msg: "{{ inventory_hostname }}: Finished run {{ rcount }} of {{ num_retries }}."
|
|
run_once: true
|
|
|
|
- name: Log status update to API
|
|
ansible.builtin.uri:
|
|
url : "{{ webhook }}"
|
|
headers:
|
|
Authorization : "Token {{ webhook_key }}"
|
|
Content-type : 'application/json'
|
|
method : POST
|
|
status_code : 200
|
|
validate_certs : false
|
|
return_content : false
|
|
body_format : json
|
|
body: |
|
|
"{{ inventory_hostname }}": "Finished run {{ rcount }} of {{ num_retries }}."
|
|
|
|
- name: Pause for effect
|
|
ansible.builtin.pause:
|
|
seconds: "{{ pause_time }}"
|
|
|
|
- name: Include ourself for recursion
|
|
ansible.builtin.include_tasks: tasks/long_running_tasks.yml
|
|
when: rcount|int <= num_retries
|
|
|
|
########################
|
|
# GENERAL TASKS: END #
|
|
########################
|