I’ve written a simple module that spits back ansible facts, but I can’t get the following task to show any of the values on debug.
Here’s the output from test-module:
I’ve written a simple module that spits back ansible facts, but I can’t get the following task to show any of the values on debug.
Here’s the output from test-module:
Using 1.2, this is {{ ansible_data_mounts }}, we fixed the variable syntax because the other stuff was confusing, but I think you want ${ansible_data_mounts}
also, 1.2 supports just “with_items: ansible_data_mounts”
also, 1.2 supports just “with_items: ansible_data_mounts”
aside from the debug module and passing in verbose flags, is there other debugging i can enable somehow?
{{ ansible_data_mounts }}
or
${ansible_data_mounts }}
or
ansible_data_mounts (i just updated to 1.2)
do not return a list.
fatal: [10.100.1.43] => with_items expects a list
again, test-module verifies the list output:
PARSED OUTPUT
{
“ansible_facts”: {
“ansible_data_mounts”: [
{
“dev_id”: 93515511438,
“name”: “/export/hda3$”
}
]
},
“changed”: true
}
with_items: ansible_data_mounts
with_items: ansible_data_mounts
ok, i’ll stick with that, but what invocation for the task: debug will give me elements?
debug: msg=$item.name or ${item.name} or “{{ item.name }}” or $item[‘name’] or item.name?
i’ve tried them all and none show data, “item.name” or something similar ie…not my data from the module.
David:
The text of this pull request has a nice trick on how to use templates to inspect variables: https://github.com/ansible/ansible/pull/2455
Lorin
I narrowed down the behavior–possibly a scoping issue.
If a module that emits custom facts is called inside of a with_items loop, the ansible_facts reported by the module are not registered.
I have a simple example.
a test module that spits out json and takes no arguments:
PARSED OUTPUT
{
“ansible_facts”: {
“ansible_foo”: [
{
“color”: “blue”,
“name”: “test”
}
]
},
“changed”: true
}
a simple playbook: test.yml
Right, fact modules aren’t really intended for use with_items, as that would make it return an array and not the hash it is expecting.
Right, fact modules aren't really intended for use with_items, as that
would make it return an array and not the hash it is expecting.
Fair enough.
I ended up solving by passing complex args to my module--the complex arg
being the thing that I was looping on with_items.