-
Notifications
You must be signed in to change notification settings - Fork 23.7k
/
main.yml
146 lines (132 loc) · 4.69 KB
/
main.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
- name: test ansible-config init for valid output and no dupes
block:
- name: Create temporary file
tempfile:
path: '{{output_dir}}'
state: file
suffix: temp.ini
register: ini_tempfile
- name: run config full dump
shell: ansible-config init -t all > {{ini_tempfile.path}}
- name: run ini tester, for correctness and dupes
shell: "{{ansible_playbook_python}} '{{role_path}}/files/ini_dupes.py' '{{ini_tempfile.path}}'"
- name: test ansible-config validate
block:
# not testing w/o -t all as ansible-test uses it's own plugins and would give false positives
- name: validate config files
shell: ansible-config validate -t all -v
register: valid_cfg
loop:
- empty.cfg
- base_valid.cfg
- base_all_valid.cfg
- invalid_base.cfg
- invalid_plugins_config.ini
ignore_errors: true
environment:
ANSIBLE_CONFIG: "{{role_path ~ '/files/' ~ item}}"
- name: ensure expected cfg check results
assert:
that:
- valid_cfg['results'][0] is success
- valid_cfg['results'][1] is success
- valid_cfg['results'][2] is success
- valid_cfg['results'][3] is failed
- valid_cfg['results'][4] is failed
- name: validate env vars
shell: ansible-config validate -t all -v -f env
register: valid_env
environment:
ANSIBLE_COW_SELECTION: 1
- name: validate env vars
shell: ansible-config validate -t all -v -f env
register: invalid_env
ignore_errors: true
environment:
ANSIBLE_COW_DESTRUCTION: 1
- name: ensure env check is what we expected
assert:
that:
- valid_env is success
- invalid_env is failed
- name: dump galaxy_server config
environment:
ANSIBLE_CONFIG: '{{ role_path }}/files/galaxy_server.ini'
vars:
expected:
my_org_hub:
url:
value: "https://automation.my_org/"
origin: role_path ~ "/files/galaxy_server.ini"
username:
value: my_user
origin: role_path ~ "/files/galaxy_server.ini"
password:
value: my_pass
origin: role_path ~ "/files/galaxy_server.ini"
api_version:
value: None
origin: default
release_galaxy:
test_galaxy:
my_galaxy_ng:
block:
- ansible.builtin.command: ansible-config dump --type {{ item }} --format json
loop:
- base
- all
register: galaxy_server_dump
#- debug: msg='{{ (galaxy_server_dump.results[0].stdout | from_json) }}'
#- debug: msg='{{ (galaxy_server_dump.results[1].stdout | from_json) }}'
- name: extract galaxy servers from config dump
set_fact:
galaxy_server_dump_base: '{{ (galaxy_server_dump.results[0].stdout | from_json | select("contains", "GALAXY_SERVERS"))[0].get("GALAXY_SERVERS") }}'
galaxy_server_dump_all: '{{ (galaxy_server_dump.results[1].stdout | from_json | select("contains", "GALAXY_SERVERS"))[0].get("GALAXY_SERVERS") }}'
- name: set keys vars as we reuse a few times
set_fact:
galaxy_server_dump_base_keys: '{{ galaxy_server_dump_base.keys()|list|sort }}'
galaxy_server_dump_all_keys: '{{ galaxy_server_dump_all.keys()|list|sort }}'
- name: Check galaxy server values are present and match expectations
vars:
gs:
my_org_hub:
url: "https://automation.my_org/"
username: "my_user"
password: "my_pass"
release_galaxy:
url: "https://galaxy.ansible.com/"
token: "my_token"
test_galaxy:
url: "https://galaxy-dev.ansible.com/"
token: "my_test_token"
my_galaxy_ng:
url: "http://my_galaxy_ng:8000/api/automation-hub/"
token: "my_keycloak_access_token"
auth_url: "http://my_keycloak:8080/auth/realms/myco/protocol/openid-connect/token"
client_id: "galaxy-ng"
gs_all:
url:
token:
auth_url:
username:
password:
api_version:
timeout:
origin: '{{ role_path ~ "/files/galaxy_server.ini" }}'
gs_keys: '{{ gs.keys()|list|sort }}'
block:
- name: Check galaxy server config reflects what we expect
assert:
that:
- (galaxy_server_dump_base_keys | count) == 4
- galaxy_server_dump_base_keys == gs_keys
- (galaxy_server_dump_all_keys | count) == 4
- galaxy_server_dump_all_keys == gs_keys
- name: Check individual settings
assert:
that:
- gs[item[0]][item[1]] == galaxy_server_dump_base[item[0]][item[1]][1]
- gs[item[0]][item[1]] == galaxy_server_dump_all[item[0]][item[1]][1]
when:
- item[1] in gs[item[0]]
loop: '{{gs_keys | product(gs_all) }}'