How to put period between two variables

37 views
Skip to first unread message

Kenton Brede

unread,
Feb 6, 2017, 10:13:15 PM2/6/17
to ansible...@googlegroups.com

So this will print what I want:

- debug:
  msg: "{{ groups.tag_Name_shibboleth_aws_dev1[0] }}"

But I'm using a with_items and need something like this:

- { host: 'tag_Name_shibboleth_aws_dev1', othervar: 'blah' }

- debug:
  msg: "{{ groups.item.host[0] }}"

Joining the two like so doesn't work:

"{{ groups + '.' + item.host }}"

How do I do this?

Thanks,

Kenton Brede




Johannes Kastl

unread,
Feb 7, 2017, 5:15:28 AM2/7/17
to ansible...@googlegroups.com
On 07.02.17 04:13 Kenton Brede wrote:

> "{{ groups + '.' + item.host }}"
>
> How do I do this?

Use the actual join filter:

"{{ [ groups, '.', item.host | join] }}"

https://docs.ansible.com/ansible/playbooks_filters.html

Johannes

signature.asc

Stankovic, Marko

unread,
Feb 7, 2017, 9:22:02 AM2/7/17
to ansible...@googlegroups.com
You are looking for the "bracket notation", as described here:
http://docs.ansible.com/ansible/playbooks_variables.html#what-makes-a-valid-variable-name

So, this should work in your example:
"{{ groups[item.host][0] }}"

Cheers,
Marko
CONFIDENTIALITY NOTICE: This message is the property of International Game Technology PLC and/or its subsidiaries and may contain proprietary, confidential or trade secret information. This message is intended solely for the use of the addressee. If you are not the intended recipient and have received this message in error, please delete this message from your system. Any unauthorized reading, distribution, copying, or other use of this message or its attachments is strictly prohibited.
Reply all
Reply to author
Forward
0 new messages