diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index eceac95af95..55edb249cb0 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -30,7 +30,7 @@ from ansible.utils.listify import listify_lookup_plugin_terms from ansible.utils.unsafe_proxy import UnsafeProxy, wrap_var from ansible.vars.clean import namespace_facts, clean_facts from ansible.utils.display import Display -from ansible.utils.vars import combine_vars +from ansible.utils.vars import combine_vars, isidentifier display = Display() @@ -647,6 +647,9 @@ class TaskExecutor: # update the local copy of vars with the registered value, if specified, # or any facts which may have been generated by the module execution if self._task.register: + if not isidentifier(self._task.register): + raise AnsibleError("Invalid variable name in 'register' specified: '%s'" % self._task.register) + vars_copy[self._task.register] = wrap_var(result) if self._task.async_val > 0: diff --git a/test/integration/targets/templating_settings/runme.sh b/test/integration/targets/templating_settings/runme.sh index 027619d5718..2fb202c3f98 100755 --- a/test/integration/targets/templating_settings/runme.sh +++ b/test/integration/targets/templating_settings/runme.sh @@ -3,5 +3,4 @@ set -eux ansible-playbook test_templating_settings.yml -i ../../inventory -v "$@" -ansible-playbook warn_on_register.yml -i ../../inventory -v "$@" 2>&1| grep 'is not templatable, but we found' [ "$(ansible-playbook dont_warn_register.yml -i ../../inventory -v "$@" 2>&1| grep -c 'is not templatable, but we found')" == "0" ] diff --git a/test/integration/targets/templating_settings/warn_on_register.yml b/test/integration/targets/templating_settings/warn_on_register.yml deleted file mode 100644 index 1790451f920..00000000000 --- a/test/integration/targets/templating_settings/warn_on_register.yml +++ /dev/null @@ -1,8 +0,0 @@ -- hosts: testhost - gather_facts: false - vars: - thisshouldwarn: noreally - tasks: - - name: template in register warns - debug: msg=unimportant - register: '{{ thisshouldwarn }}' diff --git a/test/integration/targets/uri/tasks/main.yml b/test/integration/targets/uri/tasks/main.yml index 9b8c23a27ca..6210cc23bde 100644 --- a/test/integration/targets/uri/tasks/main.yml +++ b/test/integration/targets/uri/tasks/main.yml @@ -56,7 +56,7 @@ - name: fetch pass_json uri: return_content=yes url=http://localhost:{{ http_port }}/{{ item }}.json - register: pass + register: fetch_pass_json with_sequence: start=0 end=4 format=pass%d - name: check pass_json @@ -66,7 +66,7 @@ - item.0.stat.checksum == item.1.content | checksum with_together: - "{{pass_checksum.results}}" - - "{{pass.results}}" + - "{{fetch_pass_json.results}}" - name: checksum fail_json