I’m playing with the one-deploy-validation repo.
It fails when there is only 1 host in the infrastructure.
It fails in the one-deploy-validation/playbooks/validation.yml
playbook with this error:
[ERROR]: Task failed: Finalization of task args for 'ansible.builtin.set_fact' failed: Error while resolving value for 'host_name_to_hostname_cmd': object of type 'str' has no attribute 'NAME'
Task failed.
Origin: one-deploy-validation/playbooks/validation.yml:43:11
41 no_log: true
42
43 - name: Set fact with host to "hostname_cmd" mapping
^ column 11
It fails because it expects a list of dict in the onehost list -j | jq .
command, something like this:
{
"HOST_POOL": {
"HOST": [
{
"ID": "1",
"NAME": "1.1.1.1",
......
But for 1 host, that command returns just a dict with the host info:
{
"HOST_POOL": {
"HOST": {
"ID": "0",
"NAME": "1.1.1.1",
The code that fails is:
- name: Set fact with host to "hostname_cmd" mapping
set_fact:
host_name_to_hostname_cmd: >-
{{
dict(
(host_list_json.stdout | from_json).HOST_POOL.HOST
| map(attribute='NAME')
| zip(
(host_list_json.stdout | from_json).HOST_POOL.HOST
| map(attribute='TEMPLATE')
| map(attribute='HOSTNAME')
)
)
}}
And the following code seems to fix it:
- name: Set fact with host to "hostname_cmd" mapping
set_fact:
host_name_to_hostname_cmd: >-
{{
dict(
(
(
[ (host_list_json.stdout | from_json).HOST_POOL.HOST ]
if ((host_list_json.stdout | from_json).HOST_POOL.HOST is mapping)
else (host_list_json.stdout | from_json).HOST_POOL.HOST
)
| map(attribute='NAME')
| zip(
(
[ (host_list_json.stdout | from_json).HOST_POOL.HOST ]
if ((host_list_json.stdout | from_json).HOST_POOL.HOST is mapping)
else (host_list_json.stdout | from_json).HOST_POOL.HOST
)
| map(attribute='TEMPLATE')
| map(attribute='HOSTNAME')
)
)
)
}}