-
Notifications
You must be signed in to change notification settings - Fork 141
/
configure_controller.yml
189 lines (167 loc) · 6.68 KB
/
configure_controller.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
- name: Playbook to configure ansible Controller post installation
hosts: localhost
connection: local
vars:
aap_validate_certs: false
controller_configuration_secure_logging: false
# Define following vars here, or in configs/controller_auth.yml
# aap_hostname: controller.example.com
# aap_username: admin
# aap_password: changeme
collections:
- awx.awx
- infra.aap_configuration
pre_tasks:
- name: Determine collection (block)
block:
- name: Check if the collection ansible.controller is installed
ansible.builtin.set_fact:
ansible_controller_collection_installed: "{{ lookup('ansible.builtin.pipe', 'ansible-galaxy collection list | grep -i ansible.controller || echo NOTINSTALLED') }}"
failed_when: ansible_controller_collection_installed is match('NOTINSTALLED')
rescue:
- name: Check if the collection awx.awx is installed
ansible.builtin.set_fact:
awx_awx_collection_installed: "{{ lookup('ansible.builtin.pipe', 'ansible-galaxy collection list | grep -i awx.awx || echo NOTINSTALLED') }}"
failed_when: awx_awx_collection_installed is match('NOTINSTALLED')
always:
- name: Set the collection providing the controller_api lookup plugin
ansible.builtin.set_fact:
controller_api_plugin: "{{ ('ansible.controller.controller_api' if ansible_controller_collection_installed is defined) | default('awx.awx.controller_api'
if awx_awx_collection_installed is defined) | default('NONE') }}"
- name: Fail if no collection is detected
ansible.builtin.fail:
msg: "One of the following collections is required to be installed: 'ansible.controller' or 'awx.awx'."
when: controller_api_plugin is match('NONE')
- name: Show the plugin we are using
ansible.builtin.debug:
msg: "Using the 'controller_api' plugin from: {{ controller_api_plugin }}"
- name: Include vars from configs directory
ansible.builtin.include_vars:
dir: ./configs
ignore_files: [controller_config.yml.template]
extensions: [yml]
tags:
- always
- name: Wait for Controller to come up
ansible.builtin.uri:
url: https://{{ aap_hostname }}/api/v2/ping/
status_code: 200
validate_certs: "{{ aap_validate_certs }}"
register: result
until: result.status == 200
retries: 10
delay: 30
ignore_errors: true
- name: Wait for the controller node to be up
ansible.builtin.uri:
url: https://{{ aap_hostname }}/api/v2/mesh_visualizer/
user: "{{ aap_username }}"
password: "{{ aap_password }}"
method: GET
validate_certs: false
force_basic_auth: true
status_code: 200
body_format: json
register: mesh_data
until: mesh_data.json is defined
retries: 80
delay: 5
- name: Show result of mesh_visualizer
ansible.builtin.debug:
var: mesh_data
- name: Sleep for 60 seconds and allow awx to come up.
ansible.builtin.wait_for:
timeout: 60
delegate_to: localhost
roles:
- dispatch # The dispatch role calls all of the other roles.
tasks:
- name: Validate error handling
block:
- name: Add Invalid Job Templates to Controller
ansible.builtin.include_role:
name: job_templates
vars:
controller_templates: "{{ controller_templates_invalid }}"
- name: Ensure the job_templates_errors is defined and has items
ansible.builtin.assert:
that:
- job_templates_errors is defined
- job_templates_errors | length > 0
fail_msg: No errors found, validate test example
success_msg: Errors found, proceeding
vars:
job_templates_errors: "{{ __job_templates_errors_set_stats.ansible_stats.data.job_templates_errors }}"
- name: Add Controller Settings Individually
ansible.builtin.include_role:
name: settings
vars:
controller_settings: "{{ controller_settings_individuale }}"
- name: Run ad hoc commands
ansible.builtin.include_role:
name: ad_hoc_command
when: controller_ad_hoc_commands is defined
- name: Cancel Ad hoc commands
ansible.builtin.include_tasks: ./tasks/ad_hoc_cancel.yml
when: controller_ad_hoc_commands is defined
- name: Launch Controller Bulk Hosts
ansible.builtin.include_role:
name: bulk_host_create
vars:
controller_bulk_hosts: "{{ temp_controller_bulk_hosts }}"
when:
- controller_bulk_launch_jobs is defined
- name: Launch Controller Jobs
ansible.builtin.include_role:
name: job_launch
when: controller_launch_jobs is defined
- name: Show launched Controller jobs
ansible.builtin.debug:
var: launched_controller_jobs
- name: Combine id output with defaults temp
ansible.builtin.set_fact:
tmp_job: "{{ {'id': item.id} }}"
with_items: "{{ launched_controller_jobs.results }}"
register: tmp_jobs
- name: Cancel Controller Jobs
ansible.builtin.include_role:
name: jobs_cancel
vars:
controller_cancel_jobs: "{{ tmp_jobs.results | map(attribute='ansible_facts.tmp_job') | list }}"
when: launched_controller_jobs is defined
- name: Find Job ID's
ansible.builtin.debug:
var: __job_templates_job_async_result
- name: Launch Controller Bulk Jobs
ansible.builtin.include_role:
name: bulk_job_launch
vars:
controller_bulk_hosts: "{{ temp_controller_bulk_hosts }}"
controller_bulk_launch_jobs:
- name: My Bulk Job Launch
jobs:
- unified_job_template: "{{ __job_templates_job_async_result.results[0].id }}"
- unified_job_template: "{{ __job_templates_job_async_result.results[1].id }}"
organization: Default
wait: false
when:
- controller_bulk_launch_jobs is defined
- name: Launch Controller workflows
ansible.builtin.include_role:
name: workflow_launch
when: controller_workflow_launch_jobs is defined
- name: Launched Workflows
ansible.builtin.debug:
var: launched_controller_workflows
- name: Wait for workflow to finish
job_wait:
job_id: "{{ launched_controller_workflows.results[0].id }}"
job_type: workflow_jobs
timeout: 180
aap_username: "{{ aap_username }}"
aap_password: "{{ aap_password }}"
controller_host: "{{ aap_hostname }}"
validate_certs: "{{ aap_validate_certs }}"
ignore_errors: true # noqa ignore-errors
...