You can use the varnames lookup to get variable names that match given
pattern: https://docs.ansible.com/ansible/latest/plugins/lookup/varnames.html

On Wed, Jun 24, 2020 at 12:33 PM Willem Bos <[email protected]> wrote:
>
> Hi,
>
> The playbook below should generate a file with the content:
> a,b
> ssh_host_key
> ssh_rsa_host_key
>
> However, the way I construct the variable names results in either 
> syntax/templating errors or 'variable name does not exists'.
>
> ---
> - hosts: localhost
>   connection: local
>
>   vars:
>     CentOS:
>       ciphers: "a,b"
>       hostkeys:
>         - "ssh_host_key"
>         - "ssh_rsa_host_key"
>   tasks:
>   - copy:
>       dest: "{{ playbook_dir }}/test.out"
>       content: |
>
>         # This works:
>         {{ CentOS.ciphers }}
>
>         # This results in 'No variable found with this name':
>         {# Ciphers {{ lookup('vars', ansible_distribution + '.ciphers') }}
>
>         # Templating errors:
>         {% for hostkey in {{ lookup('vars', ansible_distribution + 
> '.hostkeys') }} %}
>         {{ hostkey }}
>         {% endfor %}
>
>         # Templating errors:
>         {% for hostkey in {{ 
> hostvars[inventory_hostname][ansible_distribution + '.hostkeys'] }} %}
>         {{ hostkey }}
>         {% endfor %}
>
>
> What is the proper way to 'assemble' the variable names? Or is there a better 
> way of doing this?
>
> Regards,
> Willem.
>
> --
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/76b24a20-1c5b-46ea-a197-f1c390fcd0f7o%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CADDq2EMKKvdmqK4hJmK7T_m%2BE5UsM3eBPLPTWjByjW4Ggm46Kg%40mail.gmail.com.

Reply via email to