-
Notifications
You must be signed in to change notification settings - Fork 1
/
instance.yml
100 lines (91 loc) · 3.07 KB
/
instance.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
- name: Build a jumphost - prepare with dependancies of students participating in a workshop
hosts: localhost
gather_facts: false
vars:
- ec2_wait: true
- teardown: false
- instance_count: 1
roles:
- workshop_jumphost
tasks:
- name: wait for all nodes to have SSH reachability
hosts: "jumphost"
become: true
gather_facts: false
roles:
- connectivity_test
- name: Add local accounts for students participating in a workshop
hosts: "jumphost"
gather_facts: false
become: true
vars:
# - student_total: "10"
# - student_prefix: "student"
roles:
- user_accounts
- name: Customise and add software dependancies
hosts: "jumphost"
become: true
gather_facts: true
vars:
- towerinstall: false
roles:
- common
- control_node
- name: Install coder service + NGINX frontend
hosts: "jumphost"
become: true
gather_facts: true
roles:
- vscode
tasks:
- name: show all host IP matching group pattern, i.e. all in the group jumphost
debug:
msg: "{{ hostvars[item]['ansible_host'] }}"
with_inventory_hostnames:
- jumphost
- name: Add the Ansible Tower scheduled task
hosts: localhost
vars:
- sched1: "{{ tower_user_name }}_{{ instance_tag }}_schedule"
- host: 127.0.0.1
- port: 25
- subject: "from Ansible Tower {{ instance_tag }} Job Complete"
- body: "System {{ instance_tag }} has been succesfully provisioned."
collections:
- awx.awx.tower_schedule
tasks:
# Ensure you setup the TZ under settings/jobs as an extra_var or you will get UTC skewed time.
- name: Calculate the future date for our schedule
set_fact:
# +48 hours
future_date: "{{ '%Y-%m-%d %H:%M:%S' | strftime( ( ansible_date_time['epoch'] | int + 172800 ) ) }}"
#future_date: "{{ '%Y-%m-%d %H:%M:%S' | strftime( ( ansible_date_time['epoch'] | int + 600 ) ) }}"
# +1 hour
#future_date: "{{ '%Y-%m-%d %H:%M:%S' | strftime( ( ansible_date_time['epoch'] | int + 3600 ) ) }}"
- name: Print a date/time of our scheduled task for destroying this jumphost
debug:
var: future_date
- name: Setup the schedule for removing our jumphost
tower_schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "contoso-jumphost-teardown"
rrule: "{{ query('awx.awx.tower_schedule_rrule', 'none', timezone='Australia/Sydney', end_on=1, start_date=future_date) }}"
#rrule: "DTSTART;TZID=Australia/Sydney:20200930T130551 RRULE:FREQ=DAILY;COUNT=1;INTERVAL=1"
validate_certs: false
extra_data:
tower_user_name: "{{ tower_user_name }}"
instance_tag: "{{ instance_tag }}"
register: result
- name: Send an email - To requestor
mail:
host: "{{ host }}"
port: "{{ port | int }}"
to: "{{ tower_user_email }}"
from: rhailsto@redhat.com
subject: "{{ subject }}"
body: "{{ lookup('template', 'email_body.j2') }}"
##attach: "{{ hostvars['jumphost_'ec2_name_prefix]['ansible_ssh_private_key_file'] }}"
delegate_to: localhost