-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcheck_vars.yml
More file actions
235 lines (203 loc) · 9.3 KB
/
Copy pathcheck_vars.yml
File metadata and controls
235 lines (203 loc) · 9.3 KB
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
226
227
228
229
230
231
232
233
234
235
---
- name: "Validate required variables for AGOF"
hosts: localhost
connection: local
become: false
gather_facts: false
vars_files:
- "vars/main.yml"
- "~/agof_vault.yml"
vars:
# Track all errors so we can report them all at once
_validation_errors: []
_validation_warnings: []
# ---- AWS-specific variables (warning only, not required for non-AWS deploys) ----
_aws_vars:
- name: aws_access_key_vault
description: "AWS access key"
hint: "Set in ~/agof_vault.yml. Get it from the AWS IAM console: https://console.aws.amazon.com/iam/ -> Users -> Security credentials -> Access keys"
- name: aws_secret_key_vault
description: "AWS secret key"
hint: "Set in ~/agof_vault.yml. Get it from the AWS IAM console (shown only at access key creation time)"
- name: aws_account_nbr_vault
description: "AWS account number"
hint: "Set in ~/agof_vault.yml. Find it in the AWS console top-right menu, or run: aws sts get-caller-identity"
- name: ec2_name_prefix
description: "Unique prefix for AWS resources (used as pattern name and in DNS entries)"
hint: "Set in ~/agof_vault.yml. Choose a unique short name (no underscores). See agof_vault_template.yml for reference"
- name: ec2_region
description: "AWS region (e.g. us-east-1)"
hint: "Set in ~/agof_vault.yml. Pick a region your account has access to. See agof_vault_template.yml for reference"
- name: pattern_dns_zone
description: "A public DNS zone managed by AWS Route53"
hint: "Set in ~/agof_vault.yml. Must be a Route53 hosted zone in your AWS account"
# ---- Required variables (~/agof_vault.yml) ----
_vault_vars:
- name: offline_token
description: "Red Hat offline token (used to download the AAP containerized installer)"
hint: "Set in ~/agof_vault.yml. Generate at https://access.redhat.com/management/api"
- name: redhat_username
description: "Red Hat Subscription username (used to login to registry.redhat.io)"
hint: "Set in ~/agof_vault.yml. This is your Red Hat Customer Portal login"
- name: redhat_password
description: "Red Hat Subscription password (used to login to registry.redhat.io)"
hint: "Set in ~/agof_vault.yml. This is your Red Hat Customer Portal password"
- name: admin_password
description: "Admin password for AAP Controller, Hub, and EDA"
hint: "Set in ~/agof_vault.yml. Choose a strong password (cannot be 'ansible')"
- name: manifest_content
description: "Base64-encoded manifest file to entitle AAP Controller"
hint: !unsafe >-
Set in ~/agof_vault.yml. Download a manifest from
https://docs.redhat.com/en/documentation/red_hat_ansible_automation_platform/2.7/html/installing_on_openshift_container_platform/assembly-gateway-licensing-operator-copy#assembly-aap-obtain-manifest-files
Then set: manifest_content: "{{ lookup('file', '~/path/to/manifest.zip') | b64encode }}"
- name: org_number_vault
description: "Red Hat Organization Number for RHEL subscription"
hint: "Set in ~/agof_vault.yml. Find it at https://access.redhat.com/management -> Overview (top-left)"
- name: activation_key_vault
description: "Activation Key name for RHEL registration at bootstrap time"
hint: "Set in ~/agof_vault.yml. Create one at https://access.redhat.com/management/activation_keys"
- name: automation_hub_token_vault
description: "Token for retrieving Ansible Automation Hub content"
hint: "Set in ~/agof_vault.yml. Get it from https://console.redhat.com/ansible/automation-hub/token"
tasks:
- name: Resolve target AAP version from vault overrides
ansible.builtin.set_fact:
aap_version: "{{ (aap_version | default(containerized_installer_version | default('2.7'))) | string }}"
- name: "Check that vault file exists"
ansible.builtin.stat:
path: "~/agof_vault.yml"
register: _vault_file
- name: "Fail early if vault file is missing"
ansible.builtin.fail:
msg: |-
========================================================
ERROR: ~/agof_vault.yml not found
========================================================
The vault file is required for AGOF configuration.
To get started:
1. Copy the template:
cp agof_vault_template.yml ~/agof_vault.yml
2. Edit ~/agof_vault.yml and fill in your values
3. (Optional) Encrypt it:
ansible-vault encrypt ~/agof_vault.yml
See agof_vault_template.yml for descriptions of each variable.
========================================================
when: not _vault_file.stat.exists
# ---- Check AWS-specific variables (warn only) ----
- name: "Check AWS-specific variables"
ansible.builtin.set_fact:
_validation_warnings: >-
{{ _validation_warnings + [
{
'variable': item.name,
'description': item.description,
'hint': item.hint
}
] }}
when: >-
lookup('vars', item.name, default='') | length == 0
loop: "{{ _aws_vars }}"
loop_control:
label: "{{ item.name }}"
- name: "Report AWS warnings"
ansible.builtin.debug:
msg: |-
WARNING: {{ item.variable }} is not set.
{{ item.description }}
-> {{ item.hint }}
(Only required for AWS deployments)
loop: "{{ _validation_warnings }}"
loop_control:
label: "{{ item.variable }}"
when: _validation_warnings | length > 0
# ---- Check required variables ----
- name: "Validate required variables"
ansible.builtin.set_fact:
_validation_errors: >-
{{ _validation_errors + [
{
'variable': item.name,
'description': item.description,
'hint': item.hint
}
] }}
when: >-
lookup('vars', item.name, default='') | length == 0
loop: "{{ _vault_vars }}"
loop_control:
label: "{{ item.name }}"
# ---- Value-specific checks (only if the variable is defined) ----
- name: "Check ec2_name_prefix is not TESTPATTERN"
ansible.builtin.debug:
msg: |-
WARNING: ec2_name_prefix is set to 'TESTPATTERN'.
Set a unique name for your pattern in ~/agof_vault.yml.
(Only required for AWS deployments)
when:
- ec2_name_prefix is defined
- ec2_name_prefix == "TESTPATTERN"
- name: "Check ec2_name_prefix has no underscores"
ansible.builtin.debug:
msg: |-
WARNING: ec2_name_prefix contains underscores.
Amazon AWS does not allow underscores for S3 websites.
-> See https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
(Only required for AWS deployments)
when:
- ec2_name_prefix is defined
- "'_' in ec2_name_prefix"
- name: "Check admin_password is not 'ansible'"
ansible.builtin.set_fact:
_validation_errors: >-
{{ _validation_errors + [
{
'variable': 'admin_password',
'description': 'admin_password cannot be set to "ansible"',
'hint': 'Choose a stronger password in ~/agof_vault.yml'
}
] }}
when:
- admin_password is defined
- admin_password == "ansible"
- name: "Check aap_version is supported"
ansible.builtin.set_fact:
_validation_errors: >-
{{ _validation_errors + [
{
'variable': 'aap_version',
'description': "aap_version must be one of {{ agof_supported_aap_versions | join(', ') }} (got '{{ aap_version }}')",
'hint': 'Set containerized_installer_version or aap_version in ~/agof_vault.yml, then re-run make preinit'
}
] }}
when:
- aap_version is defined
- aap_version not in agof_supported_aap_versions
# ---- Report results ----
- name: "All variables validated successfully"
ansible.builtin.debug:
msg: |-
========================================================
All required variables are present and valid.
{% if _validation_warnings | length > 0 %}
({{ _validation_warnings | length }} AWS-specific warning(s) above)
{% endif %}
========================================================
when: _validation_errors | length == 0
- name: "Report missing or invalid variables"
ansible.builtin.fail:
msg: |-
========================================================
AGOF VARIABLE VALIDATION FAILED
========================================================
Found {{ _validation_errors | length }} issue(s):
{% for err in _validation_errors %}
{{ loop.index }}. {{ err.variable }}
{{ err.description }}
-> {{ err.hint }}
{% endfor %}
========================================================
Template file: agof_vault_template.yml
Vault file: ~/agof_vault.yml
========================================================
when: _validation_errors | length > 0