This is what I’m running 

My role
- name: Template Knownhosts
  template: src=./ssh_key.j2 dest=/tmp/temp.conf

My template 
{% for host in groups['all'] %}
   "{{ hostvars[host]['ansible_facts']['ssh_host_key_ecdsa_public'] }}"
{% endfor %}

My playbook

---
- name: Centos 7 Servers
  hosts: servers_all
  gather_facts: True
  ignore_errors: yes
  roles:
   - linux-role

> On Jan 3, 2019, at 3:31 PM, Hugo Gonzalez <[email protected]> wrote:
> 
> 
> On 1/3/19 4:26 PM, Freddie Eisa wrote:
>> I had tried but still receive 
>> 
>> fatal: [server]: FAILED! => {"changed": false, "msg": 
>> "AnsibleUndefinedVariable: 'dict object' has no attribute 
>> 'ssh_host_key_ecdsa_public'"}
>> 
> Please post the play you're using, or at least the relevant task and template.
> 
>>> This works for me and prints the key.---
>>> - hosts: all
>>> 
>>>   tasks:
>>>     - debug:
>>>         msg: "{% for host in groups['all'] %} {{ 
>>> hostvars[host]['ansible_facts']['ssh_host_key_ecdsa_public'] }} {% endfor 
>>> %}"
>>> 
>>> 
> -- 
> HUGO F. GONZALEZ
> SENIOR CONSULTANT
> Red Hat LATAM <https://www.redhat.com/>
>  <https://red.ht/sig>
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/51fe343a-0562-0849-9161-4a0d04366503%40redhat.com
>  
> <https://groups.google.com/d/msgid/ansible-project/51fe343a-0562-0849-9161-4a0d04366503%40redhat.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4B57DC00-7EAD-4209-97FA-C75F30038649%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to