From 542eeeb5d6a18bfa631d9366e4aa0f69d54cbb69 Mon Sep 17 00:00:00 2001 From: Matt Coddington Date: Mon, 6 May 2013 09:48:52 -0400 Subject: [PATCH] add option to ignore $legacy variable style substitution --- examples/ansible.cfg | 7 +++++++ lib/ansible/constants.py | 1 + lib/ansible/utils/template.py | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/examples/ansible.cfg b/examples/ansible.cfg index e11f0541f1..6536550c1c 100644 --- a/examples/ansible.cfg +++ b/examples/ansible.cfg @@ -102,6 +102,13 @@ sudo_exe=sudo # # hash_behaviour=replace +# How to handle variable replacement - as of 1.2, Jinja2 variable syntax is +# preferred, but we still support the old $variable replacement too. +# If you change legacy_playbook_variables to no then Ansible will no longer +# try to do replacement on $variable style variables. +# +# legacy_playbook_variables=yes + # if you need to use jinja2 extensions, you can list them here # use a coma to separate extensions, e.g. : # jinja2_extensions=jinja2.ext.do,jinja2.ext.i18n diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 499f6e2e7c..002522f219 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -94,6 +94,7 @@ DEFAULT_KEEP_REMOTE_FILES = get_config(p, DEFAULTS, 'keep_remote_files', 'ANSIBL DEFAULT_SUDO_EXE = get_config(p, DEFAULTS, 'sudo_exe', 'ANSIBLE_SUDO_EXE', 'sudo') DEFAULT_SUDO_FLAGS = get_config(p, DEFAULTS, 'sudo_flags', 'ANSIBLE_SUDO_FLAGS', '-H') DEFAULT_HASH_BEHAVIOUR = get_config(p, DEFAULTS, 'hash_behaviour', 'ANSIBLE_HASH_BEHAVIOUR', 'replace') +DEFAULT_LEGACY_PLAYBOOK_VARIABLES = get_config(p, DEFAULTS, 'legacy_playbook_variables', 'ANSIBLE_LEGACY_PLAYBOOK_VARIABLES', 'yes') DEFAULT_JINJA2_EXTENSIONS = get_config(p, DEFAULTS, 'jinja2_extensions', 'ANSIBLE_JINJA2_EXTENSIONS', None) DEFAULT_EXECUTABLE = get_config(p, DEFAULTS, 'executable', 'ANSIBLE_EXECUTABLE', '/bin/sh') diff --git a/lib/ansible/utils/template.py b/lib/ansible/utils/template.py index 927fdcd518..90a86c20c1 100644 --- a/lib/ansible/utils/template.py +++ b/lib/ansible/utils/template.py @@ -142,6 +142,11 @@ def _legacy_varFind(basedir, text, vars, lookup_fatal, depth, expand_lists): original data in the caller. ''' + # short circuit this whole function if we have specified we don't want + # legacy var replacement + if C.DEFAULT_LEGACY_PLAYBOOK_VARIABLES == 'no': + return None + start = text.find("$") if start == -1: return None