Fix template module incorrectly handling mode when dest is a directory
Fixes #9350
This commit is contained in:
parent
1e12d3028c
commit
feb9ed1de8
3 changed files with 41 additions and 5 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 5af8d55b0365a5c3278c43b5424bf5f2ddf897b8
|
Subproject commit fa6d74a97054d5d5123696d1af94b31ac1a65237
|
|
@ -133,9 +133,12 @@ class ActionModule(object):
|
||||||
# when running the file module based on the template data, we do
|
# when running the file module based on the template data, we do
|
||||||
# not want the source filename (the name of the template) to be used,
|
# not want the source filename (the name of the template) to be used,
|
||||||
# since this would mess up links, so we clear the src param and tell
|
# since this would mess up links, so we clear the src param and tell
|
||||||
# the module to follow links
|
# the module to follow links. When doing that, we have to set
|
||||||
|
# original_basename to the template just in case the dest is
|
||||||
|
# a directory.
|
||||||
new_module_args = dict(
|
new_module_args = dict(
|
||||||
src=None,
|
src=None,
|
||||||
|
original_basename=os.path.basename(source),
|
||||||
follow=True,
|
follow=True,
|
||||||
)
|
)
|
||||||
# be sure to inject the check mode param into the module args and
|
# be sure to inject the check mode param into the module args and
|
||||||
|
|
|
@ -60,7 +60,40 @@
|
||||||
register: file_result
|
register: file_result
|
||||||
|
|
||||||
- name: ensure file mode did not change
|
- name: ensure file mode did not change
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "file_result.changed != True"
|
- "file_result.changed != True"
|
||||||
|
|
||||||
|
# VERIFY dest as a directory does not break file attributes
|
||||||
|
# Note: expanduser is needed to go down the particular codepath that was broken before
|
||||||
|
- name: setup directory for test
|
||||||
|
file: state=directory dest={{output_dir | expanduser}}/template-dir mode=0755 owner=nobody group=nobody
|
||||||
|
|
||||||
|
- name: set file mode when the destination is a directory
|
||||||
|
template: src=foo.j2 dest={{output_dir | expanduser}}/template-dir/ mode=0600 owner=root group=root
|
||||||
|
|
||||||
|
- name: set file mode when the destination is a directory
|
||||||
|
template: src=foo.j2 dest={{output_dir | expanduser}}/template-dir/ mode=0600 owner=root group=root
|
||||||
|
register: file_result
|
||||||
|
|
||||||
|
- name: check that the file has the correct attributes
|
||||||
|
stat: path={{output_dir | expanduser}}/template-dir/foo.j2
|
||||||
|
register: file_attrs
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "file_attrs.stat.gid == 0"
|
||||||
|
- "file_attrs.stat.uid == 0"
|
||||||
|
- "file_attrs.stat.pw_name == 'root'"
|
||||||
|
- "file_attrs.stat.mode == '0600'"
|
||||||
|
|
||||||
|
- name: check that the containing directory did not change attributes
|
||||||
|
stat: path={{output_dir | expanduser}}/template-dir/
|
||||||
|
register: dir_attrs
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "dir_attrs.stat.gid != 0"
|
||||||
|
- "dir_attrs.stat.uid != 0"
|
||||||
|
- "dir_attrs.stat.pw_name == 'nobody'"
|
||||||
|
- "dir_attrs.stat.mode == '0755'"
|
||||||
|
|
Loading…
Add table
Reference in a new issue