I am referring this question: Using Ansible set_fact to create a dictionary from register results
- debug:
msg:
- "proc: '{{ item.ansible_facts.process }}'"
- "own: '{{ item.ansible_facts.owner }}'"
- "stat: '{{ item.ansible_facts.state }}'"
with_items: '{{ taglr.results }}'
- set_fact:
_services: " {{ _services|default([]) + [ {'proc': item.ansible_facts.process, 'own': item.ansible_facts.owner ,'stat': item.ansible_facts.state} ] }}"
with_items: '{{ taglr.results }}'
the taglr.results contents are as follows
taglr: {
"results": [
{
"_ansible_item_label": "O3_RBT",
"_ansible_no_log": false,
"ansible_loop_var": "item",
"changed": true,
"cmd": "clustat | grep O3_RBT | grep -v Status | awk '{print $1\"--\"$2\"--\"$3}' | awk -F ':' '{print $2}' | sed 's/(\\|)//g'",
"delta": "0:00:00.039447",
"end": "2020-10-06 13:13:48.782631",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "clustat | grep O3_RBT | grep -v Status | awk '{print $1\"--\"$2\"--\"$3}' | awk -F ':' '{print $2}' | sed 's/(\\|)//g'",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"item": "O3_RBT",
"rc": 0,
"start": "2020-10-06 13:13:48.743184",
"stderr": "",
"stderr_lines": [],
"stdout": "O3_RBT--rbt_daemon--disabled",
"stdout_lines": [
"O3_RBT--rbt_daemon--disabled"
]
},
{
"_ansible_item_label": "RBTTOMCAT",
"_ansible_no_log": false,
"ansible_loop_var": "item",
"changed": true,
"cmd": "clustat | grep RBTTOMCAT | grep -v Status | awk '{print $1\"--\"$2\"--\"$3}' | awk -F ':' '{print $2}' | sed 's/(\\|)//g'",
"delta": "0:00:00.032282",
"end": "2020-10-06 13:13:49.260344",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "clustat | grep RBTTOMCAT | grep -v Status | awk '{print $1\"--\"$2\"--\"$3}' | awk -F ':' '{print $2}' | sed 's/(\\|)//g'",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"item": "RBTTOMCAT",
"rc": 0,
"start": "2020-10-06 13:13:49.228062",
"stderr": "",
"stderr_lines": [],
"stdout": "RBTTOMCAT--rbt_daemon--started",
"stdout_lines": [
"RBTTOMCAT--rbt_daemon--started"
]
}
]
}
The debug task works as expected:
ok: [localhost] => {
"msg": [
"proc: 'O3_RBT'",
"own: 'rbt_daemon'",
"stat: 'disabled'"
]
}
ok: [localhost] => {
"msg": [
"proc: 'RBTTOMCAT'",
"own: 'rbt_daemon'",
"stat: 'started'"
]
}
But set_fact is throwing this error:
fatal: [localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on ( {{ _services|default([]) + [ {'proc': item.ansible_facts.process, 'own': item.ansible_facts.owner ,'stat': item.ansible_facts.state} ]
}}): coercing to Unicode: need string or buffer, list found"}
Whereas example, given in Using Ansible set_fact to create a dictionary from register results, works perfectly fine.
Ansible_version: ansible 2.9.10
Python_version: 2.7.5
Can anyone suggest where are the issue and any links to follow?