Re: [ansible-project] Default filter issue

2019-05-14 Thread Daniel Vašek
This could work, but only if there is no such group. When the group exists, 
but its empty, it throws error.

Dne úterý 14. května 2019 9:50:36 UTC+2 Stefan Hornburg (Racke) napsal(a):
>
> On 5/14/19 9:23 AM, Daniel Vašek wrote: 
> > Hello, 
> > 
> > Im trying to use default filter: 
> > 
> > hosts: ["{{ groups['examples'][0] | default('localhost') }}":5045] 
> > 
> > 
> > But it return error: 
> > 
> > 
> > FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict 
> object' has no attribute 'examples'"}. 
> > 
> > 
> > I read something about default can use only 1 level deep, but I cannot 
> write more levels properly. 
>
> I suppose you have to accommodate the case where there is no examples 
> entry in "groups" (untested): 
>
> {% if 'examples' in groups %}groups['examples'][0] | 
> default('localhost'){% else %}localhost{% endif %} 
>
> Regards 
> Racke 
>
> > 
> > 
> > 
> > -- 
> > 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 
> > ansible...@googlegroups.com   ansible-project+unsubscr...@googlegroups.com >. 
> > To post to this group, send email to ansible...@googlegroups.com 
>  . 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/ff9ef7e6-316d-455d-8fcc-945a033d5e4e%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/ff9ef7e6-316d-455d-8fcc-945a033d5e4e%40googlegroups.com?utm_medium=email&utm_source=footer>.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
> -- 
> Ecommerce and Linux consulting + Perl and web application programming. 
> Debian and Sympa administration. Provisioning with Ansible. 
>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cefa75f6-1dc0-4d0a-a85b-326896052cf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Default filter issue

2019-05-14 Thread Sebastian Meyer
On 14.05.19 09:23, Daniel Vašek wrote:
> Hello,
> 
> Im trying to use default filter:
> 
> hosts: ["{{ groups['examples'][0] | default('localhost') }}":5045]
> 

You should be able to use: groups.examples.0 | default(...)

This is the one case where dot notation is simpler/better :)

Sebastian

> 
> But it return error:
> 
> 
> FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict 
> object' has no attribute 'examples'"}.
> 
> 
> I read something about default can use only 1 level deep, but I cannot 
> write more levels properly.
> 
> 
> 

-- 
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f4953f3c-b75d-d2d4-09a6-30313f391e4f%40b1-systems.de.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Default filter issue

2019-05-14 Thread Stefan Hornburg (Racke)
On 5/14/19 9:23 AM, Daniel Vašek wrote:
> Hello,
> 
> Im trying to use default filter:
> 
> hosts: ["{{ groups['examples'][0] | default('localhost') }}":5045]
> 
> 
> But it return error:
> 
> 
> FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' 
> has no attribute 'examples'"}.
> 
> 
> I read something about default can use only 1 level deep, but I cannot write 
> more levels properly.

I suppose you have to accommodate the case where there is no examples entry in 
"groups" (untested):

{% if 'examples' in groups %}groups['examples'][0] | default('localhost'){% 
else %}localhost{% endif %}

Regards
Racke

> 
> 
> 
> -- 
> 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
> ansible-project+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to ansible-project@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ff9ef7e6-316d-455d-8fcc-945a033d5e4e%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/03476eb6-a252-aa22-0544-917729d07ed9%40linuxia.de.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


[ansible-project] Default filter issue

2019-05-14 Thread Daniel Vašek
Hello,

Im trying to use default filter:

hosts: ["{{ groups['examples'][0] | default('localhost') }}":5045]


But it return error:


FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict 
object' has no attribute 'examples'"}.


I read something about default can use only 1 level deep, but I cannot 
write more levels properly.



-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ff9ef7e6-316d-455d-8fcc-945a033d5e4e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.