Remove trailing new line while including vars (#57605)

While including var files using _raw_params adds additional new line
character, which makes Ansible to fail to include that file in.
This fix removes extraneous new line character while parsing the var file.

Fixes: #57593

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-06-10 20:53:39 +05:30 committed by Brian Coca
parent 7cf0d82108
commit 3bee49a3bb
3 changed files with 16 additions and 5 deletions

View file

@ -50,7 +50,7 @@ class ActionModule(ActionBase):
self.source_dir = self._task.args.get('dir', None) self.source_dir = self._task.args.get('dir', None)
self.source_file = self._task.args.get('file', None) self.source_file = self._task.args.get('file', None)
if not self.source_dir and not self.source_file: if not self.source_dir and not self.source_file:
self.source_file = self._task.args.get('_raw_params') self.source_file = self._task.args.get('_raw_params').rstrip('\n')
self.depth = self._task.args.get('depth', None) self.depth = self._task.args.get('depth', None)
self.files_matching = self._task.args.get('files_matching', None) self.files_matching = self._task.args.get('files_matching', None)

View file

@ -65,12 +65,12 @@
- "testing == 456" - "testing == 456"
- "base_dir == 'services'" - "base_dir == 'services'"
- "webapp_containers == 10" - "webapp_containers == 10"
- "{{ include_every_dir.ansible_included_var_files | length }} == 5" - "{{ include_every_dir.ansible_included_var_files | length }} == 6"
- "'vars/all/all.yml' in include_every_dir.ansible_included_var_files[0]" - "'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/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/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/services/webapp.yml' in include_every_dir.ansible_included_var_files[4]"
- "'vars/webapp/file_without_extension' in include_every_dir.ansible_included_var_files[4]" - "'vars/webapp/file_without_extension' in include_every_dir.ansible_included_var_files[5]"
- name: include every directory in vars except files matching webapp.yml - name: include every directory in vars except files matching webapp.yml
include_vars: include_vars:
@ -85,7 +85,7 @@
that: that:
- "testing == 789" - "testing == 789"
- "base_dir == 'environments/development'" - "base_dir == 'environments/development'"
- "{{ include_without_webapp.ansible_included_var_files | length }} == 2" - "{{ include_without_webapp.ansible_included_var_files | length }} == 3"
- "'webapp.yml' not in '{{ include_without_webapp.ansible_included_var_files | join(' ') }}'" - "'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(' ') }}'" - "'file_without_extension' not in '{{ include_without_webapp.ansible_included_var_files | join(' ') }}'"
@ -129,3 +129,12 @@
assert: assert:
that: that:
- "'a valid extension' in include_with_unknown_file_extension.message" - "'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'"

View file

@ -0,0 +1,2 @@
---
service_name: 'my_custom_service'