| 1 |
- name: check the default type in help for every action |
| 2 |
ansible.builtin.command: ansible-config {{ item }} --help |
| 3 |
loop: |
| 4 |
- list |
| 5 |
- dump |
| 6 |
- view |
| 7 |
- init |
| 8 |
- validate |
| 9 |
register: config_help |
| 10 |
changed_when: false |
| 11 |
|
| 12 |
- name: ensure every action documents all as the default type |
| 13 |
ansible.builtin.assert: |
| 14 |
that: |
| 15 |
- >- |
| 16 |
item.stdout is regex("Defaults to\\s*'all'") |
| 17 |
loop: '{{ config_help.results }}' |
| 18 |
|
| 19 |
- name: test ansible-config init for valid output and no dupes |
| 20 |
block: |
| 21 |
- name: Create temporary file |
| 22 |
tempfile: |
| 23 |
path: '{{output_dir}}' |
| 24 |
state: file |
| 25 |
suffix: temp.ini |
| 26 |
register: ini_tempfile |
| 27 |
|
| 28 |
- name: run config full dump using the default type |
| 29 |
shell: ansible-config init > {{ini_tempfile.path}} |
| 30 |
|
| 31 |
- name: run ini tester, for correctness and dupes |
| 32 |
shell: "{{ansible_playbook_python}} '{{role_path}}/files/ini_dupes.py' '{{ini_tempfile.path}}'" |
| 33 |
|
| 34 |
- name: test ansible-config validate |
| 35 |
block: |
| 36 |
- name: validate config files using the default type |
| 37 |
shell: ansible-config validate -v |
| 38 |
register: valid_cfg |
| 39 |
loop: |
| 40 |
- empty.cfg |
| 41 |
- base_valid.cfg |
| 42 |
- base_all_valid.cfg |
| 43 |
- invalid_base.cfg |
| 44 |
- invalid_plugins_config.ini |
| 45 |
ignore_errors: true |
| 46 |
environment: |
| 47 |
ANSIBLE_CONFIG: "{{role_path ~ '/files/' ~ item}}" |
| 48 |
|
| 49 |
- name: ensure expected cfg check results |
| 50 |
assert: |
| 51 |
that: |
| 52 |
- valid_cfg['results'][0] is success |
| 53 |
- valid_cfg['results'][1] is success |
| 54 |
- valid_cfg['results'][2] is success |
| 55 |
- valid_cfg['results'][3] is failed |
| 56 |
- valid_cfg['results'][4] is failed |
| 57 |
|
| 58 |
- name: validate env vars |
| 59 |
shell: ansible-config validate -t all -v -f env |
| 60 |
register: valid_env |
| 61 |
environment: |
| 62 |
ANSIBLE_COW_SELECTION: 1 |
| 63 |
|
| 64 |
- name: validate env vars |
| 65 |
shell: ansible-config validate -t all -v -f env |
| 66 |
register: invalid_env |
| 67 |
ignore_errors: true |
| 68 |
environment: |
| 69 |
ANSIBLE_COW_DESTRUCTION: 1 |
| 70 |
|
| 71 |
- name: ensure env check is what we expected |
| 72 |
assert: |
| 73 |
that: |
| 74 |
- valid_env is success |
| 75 |
- invalid_env is failed |
| 76 |
|
| 77 |
|
| 78 |
- name: dump galaxy_server config |
| 79 |
environment: |
| 80 |
ANSIBLE_CONFIG: '{{ role_path }}/files/galaxy_server.ini' |
| 81 |
vars: |
| 82 |
expected: |
| 83 |
my_org_hub: |
| 84 |
url: |
| 85 |
value: "https://automation.my_org/" |
| 86 |
origin: role_path ~ "/files/galaxy_server.ini" |
| 87 |
username: |
| 88 |
value: my_user |
| 89 |
origin: role_path ~ "/files/galaxy_server.ini" |
| 90 |
password: |
| 91 |
value: my_pass |
| 92 |
origin: role_path ~ "/files/galaxy_server.ini" |
| 93 |
release_galaxy: |
| 94 |
test_galaxy: |
| 95 |
my_galaxy_ng: |
| 96 |
block: |
| 97 |
- ansible.builtin.command: ansible-config dump --type {{ item }} --format json |
| 98 |
loop: |
| 99 |
- base |
| 100 |
- all |
| 101 |
register: galaxy_server_dump |
| 102 |
|
| 103 |
- name: extract galaxy servers from config dump |
| 104 |
set_fact: |
| 105 |
galaxy_server_dump_base: '{{ (galaxy_server_dump.results[0].stdout | from_json | select("contains", "GALAXY_SERVERS"))[0].get("GALAXY_SERVERS") }}' |
| 106 |
galaxy_server_dump_all: '{{ (galaxy_server_dump.results[1].stdout | from_json | select("contains", "GALAXY_SERVERS"))[0].get("GALAXY_SERVERS") }}' |
| 107 |
|
| 108 |
- name: set keys vars as we reuse a few times |
| 109 |
set_fact: |
| 110 |
galaxy_server_dump_base_keys: '{{ galaxy_server_dump_base.keys()|list|sort }}' |
| 111 |
galaxy_server_dump_all_keys: '{{ galaxy_server_dump_all.keys()|list|sort }}' |
| 112 |
|
| 113 |
- name: Check galaxy server values are present and match expectations |
| 114 |
vars: |
| 115 |
gs: |
| 116 |
my_org_hub: |
| 117 |
url: "https://automation.my_org/" |
| 118 |
username: "my_user" |
| 119 |
password: "my_pass" |
| 120 |
release_galaxy: |
| 121 |
url: "https://galaxy.ansible.com/" |
| 122 |
token: "my_token" |
| 123 |
test_galaxy: |
| 124 |
url: "https://galaxy-dev.ansible.com/" |
| 125 |
token: "my_test_token" |
| 126 |
my_galaxy_ng: |
| 127 |
url: "http://my_galaxy_ng:8000/api/automation-hub/" |
| 128 |
token: "my_keycloak_access_token" |
| 129 |
auth_url: "http://my_keycloak:8080/auth/realms/myco/protocol/openid-connect/token" |
| 130 |
client_id: "galaxy-ng" |
| 131 |
gs_all: |
| 132 |
url: |
| 133 |
token: |
| 134 |
auth_url: |
| 135 |
username: |
| 136 |
password: |
| 137 |
timeout: |
| 138 |
origin: '{{ role_path ~ "/files/galaxy_server.ini" }}' |
| 139 |
gs_keys: '{{ gs.keys()|list|sort }}' |
| 140 |
block: |
| 141 |
- name: Check galaxy server config reflects what we expect |
| 142 |
assert: |
| 143 |
that: |
| 144 |
- (galaxy_server_dump_base_keys | count) == 4 |
| 145 |
- galaxy_server_dump_base_keys == gs_keys |
| 146 |
- (galaxy_server_dump_all_keys | count) == 4 |
| 147 |
- galaxy_server_dump_all_keys == gs_keys |
| 148 |
|
| 149 |
- name: Check individual settings |
| 150 |
assert: |
| 151 |
that: |
| 152 |
- gs[item[0]][item[1]] == (galaxy_server_dump_base[item[0]] | selectattr('name', '==', item[1]))[0]['value'] |
| 153 |
- gs[item[0]][item[1]] == (galaxy_server_dump_all[item[0]] | selectattr('name', '==', item[1]))[0]['value'] |
| 154 |
when: |
| 155 |
- item[1] in gs[item[0]] |
| 156 |
loop: '{{gs_keys | product(gs_all) }}' |
| 157 |
|
| 158 |
- name: test ansible-config init for valid private and no hidden |
| 159 |
vars: |
| 160 |
config_keys: "{{ config_dump['stdout'] | from_json | selectattr('name', 'defined') }}" |
| 161 |
block: |
| 162 |
- name: run config full dump using the default type |
| 163 |
shell: ansible-config dump -f json |
| 164 |
register: config_dump |
| 165 |
|
| 166 |
- name: validate we get 'internal' but not hidden (_Z_) |
| 167 |
assert: |
| 168 |
that: |
| 169 |
- config_keys | selectattr('name', 'match', '_.*') | length > 0 |
| 170 |
- config_keys | selectattr('name', 'match', '_Z_.*') | length == 0 |