-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.yml
76 lines (64 loc) · 2.23 KB
/
job.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
- hosts: all
become: yes
gather_facts: no
tasks:
- name: calling a job name to invoke from system
shell: wget https://google.com
register: url_output
- name: print debug output
debug:
msg: "{{ url_output }}"
- name: print the output of some command
shell: hostname
register: output_hostname
- name: print the debug output
debug:
msg: "{{ output_hostname }}"
- name: calling url of remote site for testing
shell: "wget {{ siteurl }}"
register: url_output
retries: 5
delay: 10
until: "{{ url_output.rc }} == 0"
ignore_errors: true
- name: print debug output
debug:
msg: "{{ url_output }}"
- name : print jobid and name
debug:
msg: "{{ awx_job_id }} {{ awx_job_template_name }}"
when: "{{ url_output.rc }} != 0"
- name: Sending an email using Ansible
community.general.mail:
host: smtp.gmail.com
port: 587
subtype: html
username: [email protected]
password: "rbfqhoincpyouxqk"
to:
subject: Email By Ansible Automation Platform - about Failing job
body: job is failing https://192.168.1.22/#/jobs/playbook/{{ awx_job_id }}/output,job name is {{ awx_job_template_name }}. Please run the approval job it will wait for it, Url for approval job is https://192.168.1.22/#/templates/job_template/19/details.
when: "{{ url_output.rc }} != 0"
- name: Wait until the string "approved" is in the file /tmp/job before continuing or 1 min
wait_for:
path: /tmp/job
search_regex: approved
timeout: 10
# timeout: 86400
when: "{{ url_output.rc }} != 0"
- name: Check if job file is present
stat:
path: /tmp/job
register: register_name
when: "{{ url_output.rc }} != 0"
- name: Print Error at last if approval is not given
debug:
msg: "{{ url_output }}"
when:
- "{{ url_output.rc }} != 0"
- not register_name.stat.exists
# - name: mark job success when mark ok workflow is ran
# shell: "exit 0"
# when: "{{ url_output.rc }} != 0"