first_found: allow spaces in names (#77141)

* first_found: allow spaces in names

Fixes #77136
pull/77191/head
Martin Krizek 2 years ago committed by GitHub
parent 1286513947
commit 74a204e6f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- first_found - fix to allow for spaces in file names (https://github.com/ansible/ansible/issues/77136)

@ -134,6 +134,7 @@ RETURN = """
elements: path
"""
import os
import re
from jinja2.exceptions import UndefinedError
@ -144,18 +145,13 @@ from ansible.plugins.lookup import LookupBase
def _split_on(terms, spliters=','):
# TODO: fix as it does not allow spaces in names
termlist = []
if isinstance(terms, string_types):
for spliter in spliters:
terms = terms.replace(spliter, ' ')
termlist = terms.split(' ')
termlist = re.split(r'[%s]' % ''.join(map(re.escape, spliters)), terms)
else:
# added since options will already listify
for t in terms:
termlist.extend(_split_on(t, spliters))
return termlist

@ -84,3 +84,13 @@
assert:
that:
- "hatethisformat == '/etc/hosts'"
- name: test spaces in names
include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ role_path + '/files/vars file spaces.yml' }}"
- assert:
that:
- foo is defined

Loading…
Cancel
Save