-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
v2.0.0-0.6-rc1 and v2.0.0-0.5.beta3 - Iterating over a set_fact list of dictionaries is broken #13252
Comments
Finally found the issue: It appears the following lines had been removed for some reason - not sure why though: Under function:
Above self._task.post_validate(templar=templar)
Below self._task.post_validate(templar=templar):
|
Hi @Etherdaemon I was looking after your problem and you can fix this issue by modifying the debug action using the following patch: diff --git a/lib/ansible/plugins/action/debug.py b/lib/ansible/plugins/action/debug.py
index 5a5a805..223ebe1 100644
--- a/lib/ansible/plugins/action/debug.py
+++ b/lib/ansible/plugins/action/debug.py
@@ -43,7 +43,7 @@ class ActionModule(ActionBase):
results = self._templar.template(self._task.args['var'], convert_bare=True)
if results == self._task.args['var']:
results = "VARIABLE IS NOT DEFINED!"
- result[self._task.args['var']] = results
+ result[str(self._task.args['var'])] = results
else:
result['msg'] = 'here we are'
With this patch, ansible produce the following output: TASK [Debugging] ***************************************************************
ok: [localhost] => (item={u'name': u'number_one', u'value': u'one'}) => {
"item": {
"name": "number_one",
"value": "one"
},
"{u'name': u'number_one', u'value': u'one'}": "VARIABLE IS NOT DEFINED!"
}
ok: [localhost] => (item={u'name': u'number_two', u'value': u'two'}) => {
"item": {
"name": "number_two",
"value": "two"
},
"{u'name': u'number_two', u'value': u'two'}": "VARIABLE IS NOT DEFINED!"
} @jimi-c : what do you think about? |
With ansible 1.9.2, the current playbook result in the following exception:
|
@Yannig I'm not sure that solves my original problem. My original problem is that I was able to iterate over a dictionary of list of dictionaries. Your proposed patch appears to return VARIABLE_NOT_DEFINED as it's not accessing the list correctly. The behaviour in the Expected Results in my bug report is what you get in v2.0.0-0.4.beta2 and if I updated the task_executor.py to pop those 6 lines that were removed. |
OK. And what about the following output: TASK [Debugging] ***************************************************************
ok: [localhost] => (item={u'name': u'number_one', u'value': u'one'}) => {
"item": {
"name": "number_one",
"value": "one"
}
}
ok: [localhost] => (item={u'name': u'number_two', u'value': u'two'}) => {
"item": {
"name": "number_two",
"value": "two"
}
} This time, I'm using, the following patch: diff --git a/lib/ansible/plugins/action/debug.py b/lib/ansible/plugins/action/debug.py
index 5a5a805..1d9af30 100644
--- a/lib/ansible/plugins/action/debug.py
+++ b/lib/ansible/plugins/action/debug.py
@@ -25,7 +25,6 @@ class ActionModule(ActionBase):
''' Print statements during execution '''
TRANSFERS_FILES = False
-
def run(self, tmp=None, task_vars=None):
if task_vars is None:
task_vars = dict()
@@ -40,10 +39,14 @@ class ActionModule(ActionBase):
result['msg'] = self._task.args['msg']
# FIXME: move the LOOKUP_REGEX somewhere else
elif 'var' in self._task.args: # and not utils.LOOKUP_REGEX.search(self._task.args['var']):
- results = self._templar.template(self._task.args['var'], convert_bare=True)
- if results == self._task.args['var']:
- results = "VARIABLE IS NOT DEFINED!"
- result[self._task.args['var']] = results
+ if isinstance(self._task.args['var'], dict):
+ # Do not display dict as we have already an item field in current output
+ pass
+ else:
+ results = self._templar.template(self._task.args['var'], convert_bare=True)
+ if results == self._task.args['var']:
+ results = "VARIABLE IS NOT DEFINED!"
+ result[self._task.args['var']] = results
else:
result['msg'] = 'here we are' |
@Etherdaemon of course :) |
@Yannig Thank you very much for your help. |
Issue Type:
Bug Report
Ansible Version
ansible ((HEAD detached at v2.0.0-0.6.rc1)) $ ansible --version
ansible 2.0.0 (detached HEAD f222539) last updated 2015/11/23 10:17:38 (GMT +1000)
lib/ansible/modules/core: (devel 0e043f8) last updated 2015/11/23 10:13:05 (GMT +1000)
lib/ansible/modules/extras: (devel 0298f47) last updated 2015/11/23 10:12:09 (GMT +1000)
Running Ansible from source - v2.0.0-0.6.rc1
Environment:
OSX 10.11.1
Running Ansible from source - v2.0.0-0.6.rc1
Running boto (2.38.0) and boto3 (1.1.4)
Python 2.7.10
Summary:
When iterating over a set_fact list of dictionaries using with_items, an error of TypeError: unhashable type: 'dict' is received. This works in v2.0.0-0.4.beta2 but appears to have broken since v2.0.0-0.5.beta3. It looks like a change in ansible/lib/ansible/executor/task_executor.py may have had this affect.
Steps To Reproduce:
Expected Results:
Actual Results:
The text was updated successfully, but these errors were encountered: