2016-08-30 23:34:31 +02:00
|
|
|
|
---
|
|
|
|
|
- name: verify that the default value is indeed 1
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "testing == 1"
|
|
|
|
|
- "base_dir == 'defaults'"
|
|
|
|
|
|
|
|
|
|
- name: include the vars/environments/development/all.yml
|
|
|
|
|
include_vars:
|
|
|
|
|
file: environments/development/all.yml
|
2017-05-13 13:28:41 +02:00
|
|
|
|
register: included_one_file
|
|
|
|
|
|
|
|
|
|
- name: verify that the correct file has been loaded and default value is indeed 789
|
2016-08-30 23:34:31 +02:00
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "testing == 789"
|
|
|
|
|
- "base_dir == 'environments/development'"
|
2017-05-13 13:28:41 +02:00
|
|
|
|
- "{{ included_one_file.ansible_included_var_files | length }} == 1"
|
|
|
|
|
- "'vars/environments/development/all.yml' in included_one_file.ansible_included_var_files[0]"
|
2016-08-30 23:34:31 +02:00
|
|
|
|
|
|
|
|
|
- name: include the vars/environments/development/all.yml and save results in all
|
|
|
|
|
include_vars:
|
|
|
|
|
file: environments/development/all.yml
|
|
|
|
|
name: all
|
2017-05-13 13:28:41 +02:00
|
|
|
|
|
2016-08-30 23:34:31 +02:00
|
|
|
|
- name: verify that the values are stored in the all variable
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "all['testing'] == 789"
|
|
|
|
|
- "all['base_dir'] == 'environments/development'"
|
|
|
|
|
|
|
|
|
|
- name: include the all directory in vars
|
|
|
|
|
include_vars:
|
|
|
|
|
dir: all
|
|
|
|
|
depth: 1
|
2017-05-13 13:28:41 +02:00
|
|
|
|
|
2016-08-30 23:34:31 +02:00
|
|
|
|
- name: verify that the default value is indeed 123
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "testing == 123"
|
|
|
|
|
- "base_dir == 'all'"
|
|
|
|
|
|
2019-01-22 18:56:10 +01:00
|
|
|
|
- name: include var files with extension only
|
|
|
|
|
include_vars:
|
|
|
|
|
dir: webapp
|
|
|
|
|
ignore_unknown_extensions: True
|
|
|
|
|
extensions: ['', 'yaml', 'yml', 'json']
|
|
|
|
|
register: include_without_file_extension
|
|
|
|
|
|
|
|
|
|
- name: verify that only files with valid extensions are loaded
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- webapp_version is defined
|
|
|
|
|
- "'file_without_extension' in '{{ include_without_file_extension.ansible_included_var_files | join(' ') }}'"
|
|
|
|
|
|
2016-08-30 23:34:31 +02:00
|
|
|
|
- name: include every directory in vars
|
|
|
|
|
include_vars:
|
|
|
|
|
dir: vars
|
2019-01-22 18:56:10 +01:00
|
|
|
|
extensions: ['', 'yaml', 'yml', 'json']
|
2021-06-04 16:40:53 +02:00
|
|
|
|
ignore_files:
|
|
|
|
|
- no_auto_unsafe.yml
|
2017-05-13 13:28:41 +02:00
|
|
|
|
register: include_every_dir
|
|
|
|
|
|
|
|
|
|
- name: verify that the correct files have been loaded and overwrite based on alphabetical order
|
2016-08-30 23:34:31 +02:00
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "testing == 456"
|
|
|
|
|
- "base_dir == 'services'"
|
|
|
|
|
- "webapp_containers == 10"
|
2020-11-03 14:51:31 +01:00
|
|
|
|
- "{{ include_every_dir.ansible_included_var_files | length }} == 7"
|
2017-05-13 13:28:41 +02:00
|
|
|
|
- "'vars/all/all.yml' in include_every_dir.ansible_included_var_files[0]"
|
|
|
|
|
- "'vars/environments/development/all.yml' in include_every_dir.ansible_included_var_files[1]"
|
|
|
|
|
- "'vars/environments/development/services/webapp.yml' in include_every_dir.ansible_included_var_files[2]"
|
2020-11-03 14:51:31 +01:00
|
|
|
|
- "'vars/services/webapp.yml' in include_every_dir.ansible_included_var_files[5]"
|
|
|
|
|
- "'vars/webapp/file_without_extension' in include_every_dir.ansible_included_var_files[6]"
|
2016-08-30 23:34:31 +02:00
|
|
|
|
|
|
|
|
|
- name: include every directory in vars except files matching webapp.yml
|
|
|
|
|
include_vars:
|
|
|
|
|
dir: vars
|
|
|
|
|
ignore_files:
|
|
|
|
|
- webapp.yml
|
2019-01-22 18:56:10 +01:00
|
|
|
|
- file_without_extension
|
2021-06-04 16:40:53 +02:00
|
|
|
|
- no_auto_unsafe.yml
|
2017-05-13 13:28:41 +02:00
|
|
|
|
register: include_without_webapp
|
|
|
|
|
|
2016-08-30 23:34:31 +02:00
|
|
|
|
- name: verify that the webapp.yml file was not included
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "testing == 789"
|
|
|
|
|
- "base_dir == 'environments/development'"
|
2020-11-03 14:51:31 +01:00
|
|
|
|
- "{{ include_without_webapp.ansible_included_var_files | length }} == 4"
|
2017-05-13 13:28:41 +02:00
|
|
|
|
- "'webapp.yml' not in '{{ include_without_webapp.ansible_included_var_files | join(' ') }}'"
|
2019-01-22 18:56:10 +01:00
|
|
|
|
- "'file_without_extension' not in '{{ include_without_webapp.ansible_included_var_files | join(' ') }}'"
|
2016-08-30 23:34:31 +02:00
|
|
|
|
|
|
|
|
|
- name: include only files matching webapp.yml
|
|
|
|
|
include_vars:
|
|
|
|
|
dir: environments
|
|
|
|
|
files_matching: webapp.yml
|
2017-05-13 13:28:41 +02:00
|
|
|
|
register: include_match_webapp
|
2016-08-30 23:34:31 +02:00
|
|
|
|
|
|
|
|
|
- name: verify that only files matching webapp.yml and in the environments directory get loaded.
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "testing == 101112"
|
|
|
|
|
- "base_dir == 'development/services'"
|
|
|
|
|
- "webapp_containers == 20"
|
2017-05-13 13:28:41 +02:00
|
|
|
|
- "{{ include_match_webapp.ansible_included_var_files | length }} == 1"
|
|
|
|
|
- "'vars/environments/development/services/webapp.yml' in include_match_webapp.ansible_included_var_files[0]"
|
|
|
|
|
- "'all.yml' not in '{{ include_match_webapp.ansible_included_var_files | join(' ') }}'"
|
2016-08-30 23:34:31 +02:00
|
|
|
|
|
|
|
|
|
- name: include only files matching webapp.yml and store results in webapp
|
|
|
|
|
include_vars:
|
|
|
|
|
dir: environments
|
|
|
|
|
files_matching: webapp.yml
|
|
|
|
|
name: webapp
|
|
|
|
|
|
|
|
|
|
- name: verify that only files matching webapp.yml and in the environments directory get loaded into stored variable webapp.
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "webapp['testing'] == 101112"
|
|
|
|
|
- "webapp['base_dir'] == 'development/services'"
|
|
|
|
|
- "webapp['webapp_containers'] == 20"
|
2019-01-22 18:56:10 +01:00
|
|
|
|
|
|
|
|
|
- name: include var files without extension
|
|
|
|
|
include_vars:
|
|
|
|
|
dir: webapp
|
|
|
|
|
ignore_unknown_extensions: False
|
|
|
|
|
register: include_with_unknown_file_extension
|
|
|
|
|
ignore_errors: True
|
|
|
|
|
|
|
|
|
|
- name: verify that files without valid extensions are loaded
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "'a valid extension' in include_with_unknown_file_extension.message"
|
2019-06-10 17:23:39 +02:00
|
|
|
|
|
|
|
|
|
- name: include var with raw params
|
|
|
|
|
include_vars: >
|
|
|
|
|
services/service_vars.yml
|
|
|
|
|
|
|
|
|
|
- name: Verify that files with raw params is include without new line character
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "service_name == 'my_custom_service'"
|
2019-11-26 19:11:02 +01:00
|
|
|
|
|
|
|
|
|
- name: Check NoneType for raw params and file
|
|
|
|
|
include_vars:
|
|
|
|
|
file: "{{ lookup('first_found', possible_files, errors='ignore') }}"
|
|
|
|
|
vars:
|
|
|
|
|
possible_files:
|
|
|
|
|
- "does_not_exist.yml"
|
|
|
|
|
ignore_errors: True
|
|
|
|
|
register: include_with_non_existent_file
|
|
|
|
|
|
|
|
|
|
- name: Verify that file and raw_params provide correct error message to user
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "'Could not find file' in include_with_non_existent_file.message"
|
2020-11-03 14:51:31 +01:00
|
|
|
|
|
|
|
|
|
- name: include var (FQCN) with raw params
|
|
|
|
|
ansible.builtin.include_vars: >
|
|
|
|
|
services/service_vars_fqcn.yml
|
|
|
|
|
|
|
|
|
|
- name: Verify that FQCN of include_vars works
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "'my_custom_service' == service_name_fqcn"
|
|
|
|
|
- "'my_custom_service' == service_name_tmpl_fqcn"
|
2021-06-04 16:40:53 +02:00
|
|
|
|
|
|
|
|
|
- include_vars:
|
|
|
|
|
file: no_auto_unsafe.yml
|
|
|
|
|
register: baz
|
|
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
|
that:
|
|
|
|
|
- baz.ansible_facts.foo|type_debug != "AnsibleUnsafeText"
|