When using Jinja2 expressions it is not valid to use {{ }} around a
variable inside another expression.
You had:
{{ hostvars[{{target}}]['mysqluserpass'] }}
You need
{{ hostvars[target]['mysqluserpass'] }}
Which also, thankfully, is easier to read too.
Can also be written
{{ hostvars[target].mysqluserpass }}
On Fri, Aug 1, 2014 at 8:39 AM, Piet83 <[email protected]> wrote:
> Thank you both!
>
> May I ask an other question about hostvars in templates:
>
> When I use the follwing i a playbook everything goes well:
>
> The variable target is provided by the --extra-vars flag on the command
> line and mysqluserpass is defined in /etc/ansible/host_vars/ansible-test
> and encrypted with ansible-vault
>
> {{ hostvars[{{target}}]['mysqluserpass'] }}
>
>
> So when I use the above in a playbook it fills in the mysqluserpass nicely
> but when using this in a template to put the the mysql credentials in a
> file somewhere on the target machine it gives an syntax error:
>
> fatal: [ansible-test] => {'msg': "file: /etc/ansible/templates/CREDS.j2,
> line number: 2, error: expected token 'colon', got '}'", 'failed': True}
> fatal: [ansible-test] => {'msg': "file: /etc/ansible/templates/CREDS.j2,
> line number: 2, error: expected token 'colon', got '}'", 'failed': True}
>
>
> FATAL: all hosts have already failed -- aborting
>
> I've also tried: {{ hostvars[inventory_hostname]['mysqluserpass'] }} but
> no results.
>
>
>
>
>
>
> Op donderdag 31 juli 2014 22:59:08 UTC+2 schreef Michael DeHaan:
>>
>> Yep, typo on my part.
>>
>> I can't keep 100% of this program in my head but only 97.2% :)
>>
>>
>>
>>
>> 2014-07-31 7:21 GMT-04:00 Lucas, Sascha <[email protected]>:
>>
>>> Hi,
>>>
>>> > fatal: [ansible-test] => 'key' is a required argument.
>>>
>>> group_by needs key=webservers-{{ city | default('no_city')}}, not
>>> name=...
>>>
>>> HTH, Sascha.
>>>
>>> Stellvertretender Vorsitzender des Aufsichtsrates: Detlef Hillebrand
>>> Geschäftsführung: Michael Krüger
>>> Sitz der Gesellschaft: Halle/Saale
>>> Registergericht: Amtsgericht Stendal | Handelsregister-Nr. HRB 208414
>>> UST-ID-Nr. DE 158253683
>>>
>>> Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte
>>> Informationen. Wenn Sie nicht der richtige Empfänger sind oder diese E-Mail
>>> irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und
>>> vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte
>>> Weitergabe dieser Mail oder des Inhalts dieser Mail sind nicht gestattet.
>>> Diese Kommunikation per E-Mail ist nicht gegen den Zugriff durch Dritte
>>> geschützt. Die GISA GmbH haftet ausdrücklich nicht für den Inhalt und die
>>> Vollständigkeit von E-Mails und den gegebenenfalls daraus entstehenden
>>> Schaden. Sollte trotz der bestehenden Viren-Schutzprogramme durch diese
>>> E-Mail ein Virus in Ihr System gelangen, so haftet die GISA GmbH - soweit
>>> gesetzlich zulässig - nicht für die hieraus entstehenden Schäden.
>>>
>>> --
>>> 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/383FAD2C9609F74D8F075EFF2B86B5
>>> 795DA9ED95%40SGIS111.gisa-halle.de.
>>> For more options, visit 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/bc8dc0f8-9f85-44d7-86c1-b2ad4490c960%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/bc8dc0f8-9f85-44d7-86c1-b2ad4490c960%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit 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/CA%2BnsWgxuUcRjeAegoLAg4%3DqULcyQcDd1OKO0Zk%3Dv9NbVY%2BQodg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.