Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug show VARIABLE IS NOT DEFINED on variable when content is the same as name variable #13453

Closed
Yannig opened this issue Dec 7, 2015 · 5 comments
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@Yannig
Copy link
Contributor

Yannig commented Dec 7, 2015

Issue Type: Bug Report
Ansible Version: last devel
Ansible Configuration: nothing special
Environment: nothing special
Summary:

Ansible show VARIABLE IS NOT DEFINED on variable when content is the same as name variable

Steps To Reproduce:

An easy way to reproduce this behaviour is to launch the following test:

ansible -m debug -a var=test -e test=test localhost
Expected Results:
localhost | SUCCESS => {
    "changed": false, 
    "test": "test"
}
Actual Results:
localhost | SUCCESS => {
    "changed": false, 
    "test": "VARIABLE IS NOT DEFINED!"
}
@Yannig
Copy link
Contributor Author

Yannig commented Dec 7, 2015

The following patch is doing the job:

diff --git a/lib/ansible/plugins/action/debug.py b/lib/ansible/plugins/action/debug.py
index a024e28..1d8e28c 100644
--- a/lib/ansible/plugins/action/debug.py
+++ b/lib/ansible/plugins/action/debug.py
@@ -45,8 +45,12 @@ class ActionModule(ActionBase):
                 # If var is a list or dict, use the type as key to display
                 result[to_unicode(type(self._task.args['var']))] = results
             else:
+                # If var name is same as result, try to template it
                 if results == self._task.args['var']:
-                    results = "VARIABLE IS NOT DEFINED!"
+                    try:
+                        results = self._templar.template("{{" + results + "}}", convert_bare=True, fail_on_undefined=True)
+                    except:
+                        results = "VARIABLE IS NOT DEFINED!"
                 result[self._task.args['var']] = results
         else:
             result['msg'] = 'here we are'

Here is a simple example:

  • Without test variable defined:
ansible -m debug -a var=test localhost
localhost | SUCCESS => {
    "changed": false, 
    "test": "VARIABLE IS NOT DEFINED!"
}
  • Now with test variable:
ansible -m debug -a var=test -e test=test localhost
localhost | SUCCESS => {
    "changed": false, 
    "test": "test"
}

Yannig added a commit to Yannig/ansible that referenced this issue Dec 7, 2015
@jimi-c
Copy link
Member

jimi-c commented Dec 7, 2015

Merged your patch above, so closing this.

Thanks!

@jimi-c jimi-c closed this as completed Dec 7, 2015
@jimi-c jimi-c added this to the v2 milestone Dec 7, 2015
jimi-c pushed a commit that referenced this issue Dec 7, 2015
@Yannig
Copy link
Contributor Author

Yannig commented Dec 22, 2015

This issue is here again in last devel. I'll publish a new PR.

@Yannig
Copy link
Contributor Author

Yannig commented Dec 22, 2015

@jimi-c the new PR is here: #13629

It contains assertions about debug behaviour but I don't known if it the right place for it. Any advice?

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@lvrfrc87
Copy link
Contributor

lvrfrc87 commented Jul 3, 2018

I see this problem in 2.4.5.0
} ok: [vendor=arista] => { "vendor": "VARIABLE IS NOT DEFINED!" }

@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants