summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/action/template.py
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2016-08-22 21:55:30 -0700
committerGitHub <noreply@github.com>2016-08-22 21:55:30 -0700
commit313d4b2c9e4d8c90bf1e3ad589f4d43d6f9af9b0 (patch)
tree823f81dcf109a78254194ed82c0eca388a639823 /lib/ansible/plugins/action/template.py
parent20bde8f549cd11d05fbfbf174f4f3be3c9248374 (diff)
downloadansible-313d4b2c9e4d8c90bf1e3ad589f4d43d6f9af9b0.tar.gz
Move a path being passed around as a byte string to being passed around as a text string. (#17190)
This is enough to get minimal copy module working on python3 We have t omodify dataloader's path_dwim_relative_stack and everything that calls it to use text paths instead of byte string paths
Diffstat (limited to 'lib/ansible/plugins/action/template.py')
-rw-r--r--lib/ansible/plugins/action/template.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py
index 760db83ba8..919972d806 100644
--- a/lib/ansible/plugins/action/template.py
+++ b/lib/ansible/plugins/action/template.py
@@ -93,19 +93,20 @@ class ActionModule(ActionBase):
dest = os.path.join(dest, base)
# template the source data locally & get ready to transfer
+ b_source = to_bytes(source)
try:
- with open(source, 'r') as f:
+ with open(b_source, 'r') as f:
template_data = to_unicode(f.read())
try:
- template_uid = pwd.getpwuid(os.stat(source).st_uid).pw_name
+ template_uid = pwd.getpwuid(os.stat(b_source).st_uid).pw_name
except:
- template_uid = os.stat(source).st_uid
+ template_uid = os.stat(b_source).st_uid
temp_vars = task_vars.copy()
temp_vars['template_host'] = os.uname()[1]
temp_vars['template_path'] = source
- temp_vars['template_mtime'] = datetime.datetime.fromtimestamp(os.path.getmtime(source))
+ temp_vars['template_mtime'] = datetime.datetime.fromtimestamp(os.path.getmtime(b_source))
temp_vars['template_uid'] = template_uid
temp_vars['template_fullpath'] = os.path.abspath(source)
temp_vars['template_run_date'] = datetime.datetime.now()
@@ -118,7 +119,7 @@ class ActionModule(ActionBase):
)
temp_vars['ansible_managed'] = time.strftime(
managed_str,
- time.localtime(os.path.getmtime(source))
+ time.localtime(os.path.getmtime(b_source))
)
# Create a new searchpath list to assign to the templar environment's file