can you do this debug:
- debug: msg={{ hostvars[item]['ansible_ssh_host_key_ecdsa_public'] }}
loop: '{{groups["all"]}}'
can you do this debug:
- debug: msg={{ hostvars[item]['ansible_ssh_host_key_ecdsa_public'] }}
loop: '{{groups["all"]}}'
“The task includes an option with an undefined variable. The error was: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘ansible_ssh_host_key_ecdsa_public’\n\nThe error appears to have been in ‘/home/feisa/ansible-linux/test_single_server.yml’: line 6, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug: msg={{ hostvars[item][‘ansible_ssh_host_key_ecdsa_public’] }}\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - "{{ foo }}"\n”
so one of your hosts is not returning the fact for
`ansible_ssh_host_key_ecdsa_public`, its not an issue with the
template, but of getting the variable defined in the first place, the
'item' from the error will tell the first host host it is (add
ignore_errors:yes and you'll see all the hosts that fail).
To avoid such issues you might want to use the |default() filter or
check if the key exists before using it.
I ran the following
Tasks:
Received this
{
“ansible_ssh_host_key_ecdsa_public”: “AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMj3Y7I/7ByqhoT22sBg2D0tUO8rCVQRTUQXyecCPVfXud9tnInwxXJUI8KKoIScw2YEKQuq8SPB46CE6ce6Bqw=”