Skip to content

Commit

Permalink
fix jinja expressions in inventory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Dec 8, 2023
1 parent 5e714f7 commit 0b98185
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions tests/test_playbooks/inventory_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
vars:
foreman_groups:
- name: group_a
label: group_a
- name: group_b
label: group_b
- name: group_c
label: group_b/group_c
parent: group_b
Expand Down
2 changes: 2 additions & 0 deletions tests/test_playbooks/inventory_plugin_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
vars:
foreman_groups:
- name: group_a
label: group_a
- name: group_b
label: group_b
- name: group_c
label: group_b/group_c
parent: group_b
Expand Down
22 changes: 11 additions & 11 deletions tests/test_playbooks/tasks/inventory_plugin_tests.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
---
- name: test that all groups are present
assert:
that: >
'foreman_{{ item.label | default(item.name) | regex_replace('/', '_') }}' in groups
that:
- "'foreman_{}'.format(item.label.replace('/', '_')) in in groups"
with_items: "{{ foreman_groups }}"

- name: test that all hosts are in the "all" group
assert:
that: >
'{{ item.key }}' in groups['all']
that:
- "item.key in groups['all']"
with_dict: "{{ foreman_hosts }}"

- name: test that all hosts are in the correct hostgroup
assert:
that: >
'{{ item.key }}' in groups['foreman_{{ item.value | regex_replace('/', '_') }}']
that:
- "item.key in groups['foreman_{}'.format(item.value.replace('/', '_'))]"
with_dict: "{{ foreman_hosts }}"

- name: dump all host details
debug:
var: "hostvars['{{ item.key }}']"
var: "hostvars[item.key]"
with_dict: "{{ foreman_hosts }}"

- name: test that all hosts have the domain fact set
assert:
that: >
hostvars['{{ item.key }}']['foreman_facts']['domain'] == 'example.com'
hostvars[item.key]['foreman_facts']['domain'] == 'example.com'
with_dict: "{{ foreman_hosts }}"

- name: test that all hosts have the OS fact set
assert:
that: >
hostvars['{{ item.key }}']['foreman_facts']['operatingsystem'] == 'CentOS'
hostvars[item.key]['foreman_facts']['operatingsystem'] == 'CentOS'
with_dict: "{{ foreman_hosts }}"

- name: test that all hosts have the testparam1
assert:
that: >
hostvars['{{ item.key }}']['testparam1'] == 'testvalue1'
hostvars[item.key]['testparam1'] == 'testvalue1'
with_dict: "{{ foreman_hosts }}"

- name: test that all hosts have the testparam2
assert:
that: >
hostvars['{{ item.key }}']['testparam2'] == 'testvalue2'
hostvars[item.key]['testparam2'] == 'testvalue2'
with_dict: "{{ foreman_hosts }}"

0 comments on commit 0b98185

Please sign in to comment.