From 411b2bf7d9026d1b41aea35b0cbff39e1553636c Mon Sep 17 00:00:00 2001 From: willthames Date: Fri, 4 Jan 2013 16:26:11 +1000 Subject: [PATCH] Added additional template variables Added two additional template variables * template_fullpath - absolute path to the template * template_run_date - date that the template was rendered Documented these additional variables in the module documentation --- lib/ansible/utils/template.py | 2 ++ library/template | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/utils/template.py b/lib/ansible/utils/template.py index 10d2bc5f7d4..d7f0ab294ac 100644 --- a/lib/ansible/utils/template.py +++ b/lib/ansible/utils/template.py @@ -303,6 +303,8 @@ def template_from_file(basedir, path, vars): vars['template_path'] = realpath vars['template_mtime'] = datetime.datetime.fromtimestamp(os.path.getmtime(realpath)) vars['template_uid'] = template_uid + vars['template_fullpath'] = os.path.abspath(realpath) + vars['template_run_date'] = datetime.datetime.now() managed_default = C.DEFAULT_MANAGED_STR managed_str = managed_default.format( diff --git a/library/template b/library/template index e3c70b9b868..06955daaf27 100644 --- a/library/template +++ b/library/template @@ -9,12 +9,13 @@ description: (U(http://jinja.pocoo.org/docs/)) - documentation on the template formatting can be found in the Template Designer Documentation (U(http://jinja.pocoo.org/docs/templates/)). - - "Four additional variables can be used in templates: C(ansible_managed) + - "Six additional variables can be used in templates: C(ansible_managed) (configurable via the C(defaults) section of C(ansible.cfg)) contains a string which can be used to describe the template name, host, modification time of the template file and the owner uid, C(template_host) contains the node name of - the template's machine, C(template_uid) the owner, and C(template_path) the - file name." + the template's machine, C(template_uid) the owner, C(template_path) the + relative path of the template, C(template_fullpath) is the absolute path of the + template, and C(template_run_date) is the date that the template was rendered." options: src: description: