Merge "Introduce content argument"
This commit is contained in:
commit
bc9e947f9b
@ -427,11 +427,25 @@ class ActionModule(ActionBase):
|
||||
file_path = self._loader.get_basedir()
|
||||
|
||||
user_source = self._task.args.get('src')
|
||||
user_content = self._task.args.get('content')
|
||||
if not user_source:
|
||||
return False, dict(
|
||||
failed=True,
|
||||
msg="No user provided [ src ] was provided"
|
||||
)
|
||||
if not user_content:
|
||||
return False, dict(
|
||||
failed=True,
|
||||
msg="No user [ src ] or [ content ] was provided"
|
||||
)
|
||||
else:
|
||||
tmp_content = None
|
||||
try:
|
||||
remote_user = task_vars.get('ansible_user') or self._play_context.remote_user
|
||||
if not tmp_content:
|
||||
tmp_content = self._make_tmp_path(remote_user) + 'content'
|
||||
except TypeError:
|
||||
if not tmp_content:
|
||||
tmp_content = self._make_tmp_path() + 'content'
|
||||
with open(tmp_content, 'w') as f:
|
||||
f.writelines(user_content)
|
||||
user_source = tmp_content
|
||||
source = self._loader.path_dwim_relative(
|
||||
file_path,
|
||||
'templates',
|
||||
|
@ -38,6 +38,26 @@
|
||||
- "(lookup('ini', 'new_key section=DEFAULT file=/tmp/test.ini')) == 'new_value'"
|
||||
- "(lookup('ini', 'baz section=foo file=/tmp/test.ini')) == 'bar'"
|
||||
|
||||
# Test basic function of config_template with content instead of src
|
||||
- name: Template test INI template
|
||||
config_template:
|
||||
content: "{{ lookup('file', playbook_dir + '/templates/test.ini') }}"
|
||||
dest: "/tmp/test_with_content.ini"
|
||||
config_overrides: "{{ test_config_ini_overrides }}"
|
||||
config_type: "ini"
|
||||
|
||||
- name: Read test.ini
|
||||
slurp:
|
||||
src: /tmp/test_with_content.ini
|
||||
register: ini_file_with_content
|
||||
- debug:
|
||||
msg: "ini - {{ ini_file_with_content.content | b64decode }}"
|
||||
- name: Validate output
|
||||
assert:
|
||||
that:
|
||||
- "(lookup('ini', 'new_key section=DEFAULT file=/tmp/test_with_content.ini')) == 'new_value'"
|
||||
- "(lookup('ini', 'baz section=foo file=/tmp/test_with_content.ini')) == 'bar'"
|
||||
|
||||
# Test list additions in config_template
|
||||
- name: Template test YML template
|
||||
config_template:
|
||||
@ -96,4 +116,4 @@
|
||||
baz: "bar"
|
||||
test_config_yml_overrides:
|
||||
list_one:
|
||||
- four
|
||||
- four
|
||||
|
Loading…
Reference in New Issue
Block a user