diff options
Diffstat (limited to '')
16 files changed, 262 insertions, 0 deletions
diff --git a/test/integration/targets/include_vars-ad-hoc/aliases b/test/integration/targets/include_vars-ad-hoc/aliases new file mode 100644 index 0000000..498fedd --- /dev/null +++ b/test/integration/targets/include_vars-ad-hoc/aliases @@ -0,0 +1,2 @@ +shippable/posix/group4 +context/controller diff --git a/test/integration/targets/include_vars-ad-hoc/dir/inc.yml b/test/integration/targets/include_vars-ad-hoc/dir/inc.yml new file mode 100644 index 0000000..c1d24c8 --- /dev/null +++ b/test/integration/targets/include_vars-ad-hoc/dir/inc.yml @@ -0,0 +1 @@ +porter: cable diff --git a/test/integration/targets/include_vars-ad-hoc/runme.sh b/test/integration/targets/include_vars-ad-hoc/runme.sh new file mode 100755 index 0000000..51b68d2 --- /dev/null +++ b/test/integration/targets/include_vars-ad-hoc/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +ansible testhost -i ../../inventory -m include_vars -a 'dir/inc.yml' "$@" +ansible testhost -i ../../inventory -m include_vars -a 'dir=dir' "$@" diff --git a/test/integration/targets/include_vars/aliases b/test/integration/targets/include_vars/aliases new file mode 100644 index 0000000..765b70d --- /dev/null +++ b/test/integration/targets/include_vars/aliases @@ -0,0 +1 @@ +shippable/posix/group2 diff --git a/test/integration/targets/include_vars/defaults/main.yml b/test/integration/targets/include_vars/defaults/main.yml new file mode 100644 index 0000000..901fb22 --- /dev/null +++ b/test/integration/targets/include_vars/defaults/main.yml @@ -0,0 +1,3 @@ +--- +testing: 1 +base_dir: defaults diff --git a/test/integration/targets/include_vars/tasks/main.yml b/test/integration/targets/include_vars/tasks/main.yml new file mode 100644 index 0000000..db15ba3 --- /dev/null +++ b/test/integration/targets/include_vars/tasks/main.yml @@ -0,0 +1,217 @@ +--- +- 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 + register: included_one_file + +- name: verify that the correct file has been loaded and default value is indeed 789 + assert: + that: + - "testing == 789" + - "base_dir == 'environments/development'" + - "{{ included_one_file.ansible_included_var_files | length }} == 1" + - "'vars/environments/development/all.yml' in included_one_file.ansible_included_var_files[0]" + +- name: include the vars/environments/development/all.yml and save results in all + include_vars: + file: environments/development/all.yml + name: all + +- 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 + +- name: verify that the default value is indeed 123 + assert: + that: + - "testing == 123" + - "base_dir == 'all'" + +- 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(' ') }}'" + +- name: include every directory in vars + include_vars: + dir: vars + extensions: ['', 'yaml', 'yml', 'json'] + ignore_files: + - no_auto_unsafe.yml + register: include_every_dir + +- name: verify that the correct files have been loaded and overwrite based on alphabetical order + assert: + that: + - "testing == 456" + - "base_dir == 'services'" + - "webapp_containers == 10" + - "{{ include_every_dir.ansible_included_var_files | length }} == 7" + - "'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]" + - "'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]" + +- name: include every directory in vars except files matching webapp.yml + include_vars: + dir: vars + ignore_files: + - webapp.yml + - file_without_extension + - no_auto_unsafe.yml + register: include_without_webapp + +- name: verify that the webapp.yml file was not included + assert: + that: + - "testing == 789" + - "base_dir == 'environments/development'" + - "{{ include_without_webapp.ansible_included_var_files | length }} == 4" + - "'webapp.yml' not in '{{ include_without_webapp.ansible_included_var_files | join(' ') }}'" + - "'file_without_extension' not in '{{ include_without_webapp.ansible_included_var_files | join(' ') }}'" + +- name: include only files matching webapp.yml + include_vars: + dir: environments + files_matching: webapp.yml + register: include_match_webapp + +- 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" + - "{{ 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(' ') }}'" + +- 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" + +- 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" + +- 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'" + +- 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" + +- 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" + +- name: Include a vars file with a hash variable + include_vars: + file: vars2/hashes/hash1.yml + +- name: Verify the hash variable + assert: + that: + - "{{ config | length }} == 3" + - "config.key0 == 0" + - "config.key1 == 0" + - "{{ config.key2 | length }} == 1" + - "config.key2.a == 21" + +- name: Include the second file to merge the hash variable + include_vars: + file: vars2/hashes/hash2.yml + hash_behaviour: merge + +- name: Verify that the hash is merged + assert: + that: + - "{{ config | length }} == 4" + - "config.key0 == 0" + - "config.key1 == 1" + - "{{ config.key2 | length }} == 2" + - "config.key2.a == 21" + - "config.key2.b == 22" + - "config.key3 == 3" + +- name: Include the second file again without hash_behaviour option + include_vars: + file: vars2/hashes/hash2.yml + +- name: Verify that the properties from the first file is cleared + assert: + that: + - "{{ config | length }} == 3" + - "config.key1 == 1" + - "{{ config.key2 | length }} == 1" + - "config.key2.b == 22" + - "config.key3 == 3" + +- include_vars: + file: no_auto_unsafe.yml + register: baz + +- assert: + that: + - baz.ansible_facts.foo|type_debug != "AnsibleUnsafeText" diff --git a/test/integration/targets/include_vars/vars/all/all.yml b/test/integration/targets/include_vars/vars/all/all.yml new file mode 100644 index 0000000..14c3e92 --- /dev/null +++ b/test/integration/targets/include_vars/vars/all/all.yml @@ -0,0 +1,3 @@ +--- +testing: 123 +base_dir: all diff --git a/test/integration/targets/include_vars/vars/environments/development/all.yml b/test/integration/targets/include_vars/vars/environments/development/all.yml new file mode 100644 index 0000000..9f370de --- /dev/null +++ b/test/integration/targets/include_vars/vars/environments/development/all.yml @@ -0,0 +1,3 @@ +--- +testing: 789 +base_dir: 'environments/development' diff --git a/test/integration/targets/include_vars/vars/environments/development/services/webapp.yml b/test/integration/targets/include_vars/vars/environments/development/services/webapp.yml new file mode 100644 index 0000000..a0a809c --- /dev/null +++ b/test/integration/targets/include_vars/vars/environments/development/services/webapp.yml @@ -0,0 +1,4 @@ +--- +testing: 101112 +base_dir: 'development/services' +webapp_containers: 20 diff --git a/test/integration/targets/include_vars/vars/no_auto_unsafe.yml b/test/integration/targets/include_vars/vars/no_auto_unsafe.yml new file mode 100644 index 0000000..20e9ff3 --- /dev/null +++ b/test/integration/targets/include_vars/vars/no_auto_unsafe.yml @@ -0,0 +1 @@ +foo: bar diff --git a/test/integration/targets/include_vars/vars/services/service_vars.yml b/test/integration/targets/include_vars/vars/services/service_vars.yml new file mode 100644 index 0000000..96b05d6 --- /dev/null +++ b/test/integration/targets/include_vars/vars/services/service_vars.yml @@ -0,0 +1,2 @@ +--- +service_name: 'my_custom_service'
\ No newline at end of file diff --git a/test/integration/targets/include_vars/vars/services/service_vars_fqcn.yml b/test/integration/targets/include_vars/vars/services/service_vars_fqcn.yml new file mode 100644 index 0000000..2c04fee --- /dev/null +++ b/test/integration/targets/include_vars/vars/services/service_vars_fqcn.yml @@ -0,0 +1,3 @@ +--- +service_name_fqcn: 'my_custom_service' +service_name_tmpl_fqcn: '{{ service_name_fqcn }}'
\ No newline at end of file diff --git a/test/integration/targets/include_vars/vars/services/webapp.yml b/test/integration/targets/include_vars/vars/services/webapp.yml new file mode 100644 index 0000000..f0dcc8b --- /dev/null +++ b/test/integration/targets/include_vars/vars/services/webapp.yml @@ -0,0 +1,4 @@ +--- +testing: 456 +base_dir: services +webapp_containers: 10 diff --git a/test/integration/targets/include_vars/vars/webapp/file_without_extension b/test/integration/targets/include_vars/vars/webapp/file_without_extension new file mode 100644 index 0000000..9cfb60f --- /dev/null +++ b/test/integration/targets/include_vars/vars/webapp/file_without_extension @@ -0,0 +1,2 @@ +--- +webapp_version: "1" diff --git a/test/integration/targets/include_vars/vars2/hashes/hash1.yml b/test/integration/targets/include_vars/vars2/hashes/hash1.yml new file mode 100644 index 0000000..b0706f8 --- /dev/null +++ b/test/integration/targets/include_vars/vars2/hashes/hash1.yml @@ -0,0 +1,5 @@ +--- +config: + key0: 0 + key1: 0 + key2: { a: 21 } diff --git a/test/integration/targets/include_vars/vars2/hashes/hash2.yml b/test/integration/targets/include_vars/vars2/hashes/hash2.yml new file mode 100644 index 0000000..1f2a963 --- /dev/null +++ b/test/integration/targets/include_vars/vars2/hashes/hash2.yml @@ -0,0 +1,5 @@ +--- +config: + key1: 1 + key2: { b: 22 } + key3: 3 |