diff options
author | tomo <beltowski.t@gmail.com> | 2018-01-23 17:14:19 +0100 |
---|---|---|
committer | Adam Miller <admiller@redhat.com> | 2018-01-23 10:14:19 -0600 |
commit | ef6b478d2a272b8e6fb8aeea17c42fd08213bcfc (patch) | |
tree | e62dc2dfe2f6839b54dd7f91592811f49d780538 | |
parent | 7c8e365dff0e5925a26fff6b3365b8fde867860b (diff) | |
download | ansible-ef6b478d2a272b8e6fb8aeea17c42fd08213bcfc.tar.gz |
add rstrip and lstrip bool flags to file lookup plugin (#31738)
-rw-r--r-- | lib/ansible/plugins/lookup/file.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/ansible/plugins/lookup/file.py b/lib/ansible/plugins/lookup/file.py index 643077ffa8..4e4bdab536 100644 --- a/lib/ansible/plugins/lookup/file.py +++ b/lib/ansible/plugins/lookup/file.py @@ -15,6 +15,16 @@ DOCUMENTATION = """ _terms: description: path(s) of files to read required: True + rstrip: + description: whether or not to remove whitespace from the ending of the looked-up file + type: bool + required: False + default: True + lstrip: + description: whether or not to remove whitespace from the beginning of the looked-up file + type: bool + required: False + default: False notes: - if read in variable context, the file can be interpreted as YAML if the content is valid to the parser. - this lookup does not understand 'globing', use the fileglob lookup instead. @@ -64,7 +74,11 @@ class LookupModule(LookupBase): if lookupfile: b_contents, show_data = self._loader._get_file_contents(lookupfile) contents = to_text(b_contents, errors='surrogate_or_strict') - ret.append(contents.rstrip()) + if kwargs.get('lstrip', False): + contents = contents.lstrip() + if kwargs.get('rstrip', True): + contents = contents.rstrip() + ret.append(contents) else: raise AnsibleParserError() except AnsibleParserError: |