| 1 |
# test code for the template module |
| 2 |
# (c) 2015, Brian Coca <[email protected]> |
| 3 |
|
| 4 |
# This file is part of Ansible |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
- name: verify ansible_managed |
| 20 |
template: src=foo.j2 dest={{output_dir}}/special_vars.yaml |
| 21 |
|
| 22 |
- name: read the file into facts |
| 23 |
include_vars: "{{output_dir}}/special_vars.yaml" |
| 24 |
|
| 25 |
|
| 26 |
- name: verify all test vars are defined |
| 27 |
assert: |
| 28 |
that: |
| 29 |
- 'item in hostvars[inventory_hostname].keys()' |
| 30 |
with_items: |
| 31 |
- test_template_host |
| 32 |
- test_template_path |
| 33 |
- test_template_mtime |
| 34 |
- test_template_uid |
| 35 |
- test_template_fullpath |
| 36 |
- test_template_run_date |
| 37 |
- test_ansible_managed |
| 38 |
|
| 39 |
- name: ensure that role_name exists in role_names, ansible_play_role_names, ansible_role_names, and not in ansible_dependent_role_names |
| 40 |
assert: |
| 41 |
that: |
| 42 |
- "role_name in role_names" |
| 43 |
- "role_name in ansible_play_role_names" |
| 44 |
- "role_name in ansible_role_names" |
| 45 |
- "role_name not in ansible_dependent_role_names" |
| 46 |
|
| 47 |
- name: ensure that our dependency (prepare_tests) exists in ansible_role_names and ansible_dependent_role_names, but not in role_names or ansible_play_role_names |
| 48 |
assert: |
| 49 |
that: |
| 50 |
- "'prepare_tests' in ansible_role_names" |
| 51 |
- "'prepare_tests' in ansible_dependent_role_names" |
| 52 |
- "'prepare_tests' not in role_names" |
| 53 |
- "'prepare_tests' not in ansible_play_role_names" |
| 54 |
|
| 55 |
- name: ensure that ansible_role_names is the sum of ansible_play_role_names and ansible_dependent_role_names |
| 56 |
assert: |
| 57 |
that: |
| 58 |
- "(ansible_play_role_names + ansible_dependent_role_names)|unique|sort|list == ansible_role_names|sort|list" |
| 59 |
|
| 60 |
- name: check that ansible_parent_role_names is normally unset when not included/imported (before including other roles) |
| 61 |
assert: |
| 62 |
that: |
| 63 |
- "ansible_parent_role_names is undefined" |
| 64 |
- "ansible_parent_role_paths is undefined" |
| 65 |
|
| 66 |
- name: ansible_parent_role_names - test functionality by including another role |
| 67 |
include_role: |
| 68 |
name: include_parent_role_vars |
| 69 |
tasks_from: included_by_other_role.yml |
| 70 |
|
| 71 |
- name: check that ansible_parent_role_names is normally unset when not included/imported (after including other role) |
| 72 |
assert: |
| 73 |
that: |
| 74 |
- "ansible_parent_role_names is undefined" |
| 75 |
- "ansible_parent_role_paths is undefined" |
| 76 |
|
| 77 |
- name: ansible_parent_role_names - test functionality by importing another role |
| 78 |
import_role: |
| 79 |
name: include_parent_role_vars |
| 80 |
tasks_from: included_by_other_role.yml |
| 81 |
|
| 82 |
- name: check that ansible_parent_role_names is normally unset when not included/imported (after importing other role) |
| 83 |
assert: |
| 84 |
that: |
| 85 |
- "ansible_parent_role_names is undefined" |
| 86 |
- "ansible_parent_role_paths is undefined" |
| 87 |
|
| 88 |
- name: ansible_parent_role_names - test functionality by including another role |
| 89 |
include_role: |
| 90 |
name: include_parent_role_vars |
| 91 |
|
| 92 |
- name: check that ansible_parent_role_names is normally unset when not included/imported (after both import and include) |
| 93 |
assert: |
| 94 |
that: |
| 95 |
- "ansible_parent_role_names is undefined" |
| 96 |
- "ansible_parent_role_paths is undefined" |
| 97 |
|
| 98 |
- name: ansible_parent_role_names - test functionality by importing another role |
| 99 |
import_role: |
| 100 |
name: include_parent_role_vars |