diff --git a/lib/ansible/modules/utilities/logic/include_vars.py b/lib/ansible/modules/utilities/logic/include_vars.py index 9fea894369f..f81ebc9fda9 100644 --- a/lib/ansible/modules/utilities/logic/include_vars.py +++ b/lib/ansible/modules/utilities/logic/include_vars.py @@ -122,6 +122,12 @@ EXAMPLES = """ dir: vars ignore_files: [bastion.yaml] extensions: [yaml] + +- name: Ignore warnings raised for files with unknown extensions while loading (2.7) + include_vars: + dir: vars + ignore_unknown_extensions: True + extensions: ['', 'yaml', 'yml', 'json'] """ RETURN = ''' diff --git a/test/integration/targets/include_vars/tasks/main.yml b/test/integration/targets/include_vars/tasks/main.yml index 6d2ff868e34..4b92c372b3d 100644 --- a/test/integration/targets/include_vars/tasks/main.yml +++ b/test/integration/targets/include_vars/tasks/main.yml @@ -40,9 +40,23 @@ - "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'] register: include_every_dir - name: verify that the correct files have been loaded and overwrite based on alphabetical order @@ -51,17 +65,19 @@ - "testing == 456" - "base_dir == 'services'" - "webapp_containers == 10" - - "{{ include_every_dir.ansible_included_var_files | length }} == 4" + - "{{ include_every_dir.ansible_included_var_files | length }} == 5" - "'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[3]" + - "'vars/webapp/file_without_extension' in include_every_dir.ansible_included_var_files[4]" - name: include every directory in vars except files matching webapp.yml include_vars: dir: vars ignore_files: - webapp.yml + - file_without_extension register: include_without_webapp - name: verify that the webapp.yml file was not included @@ -71,6 +87,7 @@ - "base_dir == 'environments/development'" - "{{ include_without_webapp.ansible_included_var_files | length }} == 2" - "'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: @@ -100,3 +117,15 @@ - "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" 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 00000000000..9cfb60fbacc --- /dev/null +++ b/test/integration/targets/include_vars/vars/webapp/file_without_extension @@ -0,0 +1,2 @@ +--- +webapp_version: "1"