-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate-environment-vars.yml
225 lines (199 loc) · 8.7 KB
/
generate-environment-vars.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
---
## Usage create a set of variables that the tools team will use for our deployments.
## This will create
## - proxy environment options options when "http_proxy_server" is defined. The no proxy configuration is optional.
## - haproxy configurations for our internal tooling
## - beat service state options
##
## Playbook options:
## - "http_proxy_server" (OPTIONAL)
## - "https_proxy_server" (OPTIONAL)
## - "extra_no_proxy_hosts" (OPTIONAL)
## - "java_http_proxy" (OPTIONAL)
## - "java_https_proxy_port" (OPTIONAL)
## - "java_https_proxy" (OPTIONAL)
## - "java_https_proxy_port" (OPTIONAL)
## - "var_location" (OPTIONAL) variable directory path
## - "file_location" (OPTIONAL) variable file path
##
## When defining a proxy, the http(s)_proxy_server variables must be in the form of a URL with a specified port.
# USAGE:$ (openstack-ansible || ansible-playbook) generate-environment-vars.yml -e 'http_proxy_server=https://proxy_server.local:3128'
- name: Create user tools variables file
hosts: localhost
connection: local
user: root
gather_facts: no
vars:
http_proxy_server: "none://none:none"
java_http_proxy: "{{ (http_proxy_server).split('://')[-1].split('@')[-1].split(':')[0].strip('/') }}"
java_https_proxy: "{{ (https_proxy_server | default(http_proxy_server)).split('://')[-1].split('@')[-1].split(':')[0].strip('/') }}"
java_http_proxy_port: "{{ (http_proxy_server).split(':')[-1].strip('/') }}"
java_https_proxy_port: "{{ (https_proxy_server | default(http_proxy_server)).split(':')[-1].strip('/') }}"
no_proxy_hosts:
- localhost
- 127.0.0.1
- "{{ groups['shared-infra_hosts'] | default([]) | union(groups['all'] | default([])) | map('extract', hostvars, 'internal_lb_vip_address') | list | last }}"
- "{{ groups['shared-infra_hosts'] | default([]) | union(groups['all'] | default([])) | map('extract', hostvars, 'external_lb_vip_address') | list | last }}"
- "{{ groups['rabbitmq_all'] | default([]) | union(groups['log_containers'] | default([])) | union(groups['shared-infra_hosts'] | default([])) | map('extract', hostvars, 'ansible_host') | list | join(',') }}"
- "{{ groups['rabbitmq_all'] | default([]) | union(groups['log_containers'] | default([])) | union(groups['shared-infra_hosts'] | default([])) | map('extract', hostvars, 'container_address') | list | join(',') }}"
all_var_location:
osa: "/etc/openstack_deploy"
osp: "/home/stack"
maas_endpoints:
agent_endpoint: "agent-endpoint-ord.monitoring.api.rackspacecloud.com"
agent_endpoint_url: "https://agent-endpoint-ord.monitoring.api.rackspacecloud.com"
api: "monitoring.api.rackspacecloud.com"
api_url: "https://monitoring.api.rackspacecloud.com"
validate_certs: false
status_code:
- 200
- 404
- 503
vars_files:
- vars/main.yml
tasks:
- name: check for OSP and validate version
block:
- name: Check OSP
stat:
path: "/etc/rhosp-release"
register: osp_check
- name: Register /etc/rhosp-release version
shell: cat /etc/rhosp-release | tr -dc '0-9.'
register: osp_version
when:
- osp_check.stat.exists | bool
- name: Check OSA
stat:
path: "/etc/openstack-release"
register: osa_check
- name: Set variable path location
set_fact:
var_location: "{{ all_var_location['osa'] }}"
when:
- osa_check.stat.exists | bool
- name: Set variable path location
set_fact:
var_location: "{{ all_var_location['osp'] }}"
when:
- osp_check.stat.exists | bool
- osp_version is defined
- osp_version.stdout is version('13.0.0', '>=')
- name: Setup exit
block:
- name: Break point notice
debug:
msg: >-
No Known deployment configuration has been detected. No variables
will be generated.
- name: End play if no known deployment configuration is detected
meta: end_play
when:
- var_location is undefined
- name: State config directory
stat:
path: "{{ var_location }}"
register: config_dir
- name: Ensure openstack-deploy directory exists
file:
path: "{{ var_location }}"
state: directory
when:
- not config_dir.stat.exists | bool
- name: Java auth proxy variables
block:
- name: Set java http credential variables
set_fact:
java_http_proxy_user: "{{ http_proxy_server.split('://')[-1].split('@')[0].split(':')[0] }}"
java_http_proxy_pass: "{{ http_proxy_server.split('://')[-1].split('@')[0].split(':')[-1] }}"
when:
- http_proxy_server is defined
- name: Set java https credential variables
set_fact:
java_https_proxy_user: "{{ (https_proxy_server | default(http_proxy_server)).split('://')[-1].split('@')[0].split(':')[0] }}"
java_https_proxy_pass: "{{ (https_proxy_server | default(http_proxy_server)).split('://')[-1].split('@')[0].split(':')[-1] }}"
when:
- (https_proxy_server is defined) or (http_proxy_server is defined)
when:
- ("@" in http_proxy_server) or ("@" in https_proxy_server | default(http_proxy_server))
- name: maas API connectivity block
block:
- name: Test Rackspace Monitoring API excluding http_proxy
uri:
url: "{{ maas_endpoints.api_url }}"
validate_certs: "{{ maas_endpoints.validate_certs }}"
timeout: 5
status_code: "{{ maas_endpoints.status_code }}"
environment:
no_proxy: "{{ maas_endpoints.api }}"
- debug:
msg: "Adding API ({{ maas_endpoints.api }}) to no_proxy"
- name: Set fact to add MaaS API URL to no_proxy
set_fact:
maas_api_no_proxy: "['{{ maas_endpoints.api }}']"
rescue:
- name: Test Rackspace Monitoring API with proxy
uri:
url: "{{ maas_endpoints.api_url }}"
validate_certs: "{{ maas_endpoints.validate_certs }}"
timeout: 5
status_code: "{{ maas_endpoints.status_code }}"
environment:
http_proxy: "{{ http_proxy_server }}"
https_proxy: "{{ https_proxy_server | default(http_proxy_server) }}"
- debug:
msg: "Proxy API ({{ maas_endpoints.api }}) normally"
when:
- (https_proxy_server is defined) or (http_proxy_server is defined)
- http_proxy_server != 'none://none:none'
- name: maas agent endpoint connectivity block
block:
- name: Test Rackspace Monitoring agent endpoint excluding http_proxy
uri:
url: "{{ maas_endpoints.agent_endpoint_url }}"
validate_certs: "{{ maas_endpoints.validate_certs }}"
timeout: 5
status_code: "{{ maas_endpoints.status_code }}"
environment:
no_proxy: "{{ maas_endpoints.agent_endpoint }}"
- debug:
msg: "Adding agent endpoint ({{ maas_endpoints.agent_endpoint }}) to no_proxy"
- name: Set fact to add MaaS agent endpoint to no_proxy
set_fact:
maas_endpoint_no_proxy: "['{{ maas_endpoints.agent_endpoint }}']"
rescue:
- name: Test Rackspace Monitoring agent endpoint with proxy
uri:
url: "{{ maas_endpoints.agent_endpoint_url }}"
validate_certs: "{{ maas_endpoints.validate_certs }}"
timeout: 5
status_code: "{{ maas_endpoints.status_code }}"
environment:
http_proxy: "{{ http_proxy_server }}"
https_proxy: "{{ https_proxy_server | default(http_proxy_server) }}"
- debug:
msg: "Proxy agent endpoint ({{ maas_endpoints.agent_endpoint }}) normally"
when:
- (https_proxy_server is defined) or (http_proxy_server is defined)
- http_proxy_server != 'none://none:none'
- name: Create user_tools_variables.yml
template:
src: templates/user_tools_variables.yml.j2
dest: "{{ file_location | default(var_location + '/user_tools_variables.yml') }}"
- name: Create mtc.rc
template:
src: templates/mtc.rc.j2
dest: "{{ lookup('env', 'HOME') }}/.mtc.rc"
when:
- http_proxy_server != 'none://none:none'
# - name: Run RPC setup with OSP
# include_tasks: common-tasks/setup_osp.yml # unimplemented
# vars:
# var_psth: "{{ var_location }}"
# when:
# - osp_check.stat.exists | bool
# NOTE (npawelek): ELK is no longer deployed (removed 5/16/19)
#- name: Ensure secrets exist
# include_tasks: common-tasks/setup_secrets.yml
# vars:
# var_path: "{{ var_location }}"