[ansible-project] Re: Nested variable

2018-05-24 Thread Jordan Borean
ahh yes I should have seen you just wanted a nested var, just an FYI ~ is 
similar to + but coerces the variable to a string so you don't have to do 
that yourself. Usually + works but ~ is safer.

Thanks

Jordan

-- 
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/8537abc2-7d0b-4da5-b753-9fd4b9aec628%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Nested variable

2018-05-24 Thread David Villasmil
Hey Jordan, 

Thanks for replying!
There were "`" missing, worked beautifully after that!

- set_fact:
  hosted_zone_id: "{{ dns_results | json_query('HostedZones[?Name==`' ~ 
hosted_zone_name ~ '.`].[Id]') | regex_replace('/hostedzone/', '') }}"

"~" escapes it, so there's no need to do a lookup, works nice

Thanks!

On Thursday, May 24, 2018 at 3:11:32 AM UTC+2, Jordan Borean wrote:
>
> Try this
>
> - set_fact:
> hosted_zone_id: "{{ dns_results | json_query('HostedZones[?Name==' ~ 
> lookup('vars', hosted_zone_name) ~ '].[Id]') | 
> regex_replace('/hostedzone/', '') }}"
>
> You need to escape outside of the quoted arg of json_query and then run 
> the lookup. Note I haven't tested this
>
> Thanks
>
> Jordan
>

-- 
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/7797e526-6149-4a39-8100-9bc1c772e8e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Nested variable

2018-05-23 Thread Jordan Borean
Try this

- set_fact:
hosted_zone_id: "{{ dns_results | json_query('HostedZones[?Name==' ~ 
lookup('vars', hosted_zone_name) ~ '].[Id]') | 
regex_replace('/hostedzone/', '') }}"

You need to escape outside of the quoted arg of json_query and then run the 
lookup. Note I haven't tested this

Thanks

Jordan

-- 
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/6e6a107b-fd6a-4542-95c4-c940946482df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Nested variable

2018-05-23 Thread David Villasmil
Spoke too soon... That doesn't work either...

On Wednesday, May 23, 2018 at 10:04:16 PM UTC+2, David Villasmil wrote:
>
> Hello guys,
>
>
>  I've got this set_fact:
>
> hosted_zone_id: "{{ dns_results | 
> json_query('HostedZones[?Name==`mydomain.com.`].[Id]') | regex_replace 
> ('/hostedzone/', '') }}"
>
>
> But i want to get the id from any of my domains, so i want to use a 
> variable:
>
> hosted_zone_name: "mydomain.com"
>
>
> and do something like:
>
> hosted_zone_id: "{{ dns_results | json_query('HostedZones[?Name==`{{ 
> hosted_zone_name 
> }}.`].[Id]') | regex_replace ('/hostedzone/', '') }}"
>
>
> But it looks like nested variables like that doesn't work...
>
> Any suggestions?
>
> Thanks!
>
> David
>
>
>

-- 
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/42eec18a-3962-46bd-903c-0c67f64743a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Nested variable

2018-05-23 Thread David Villasmil
Solved!

  - set_fact:
  hosted_zone_id: "{{ dns_results | 
json_query('HostedZones[?Name==`(lookup('vars', 
hosted_zone_name)).`].[Id]') | regex_replace ('/hostedzone/', '') }}"

For future reference.

Thanks

David

On Wednesday, May 23, 2018 at 10:04:16 PM UTC+2, David Villasmil wrote:
>
> Hello guys,
>
>
>  I've got this set_fact:
>
> hosted_zone_id: "{{ dns_results | 
> json_query('HostedZones[?Name==`mydomain.com.`].[Id]') | regex_replace 
> ('/hostedzone/', '') }}"
>
>
> But i want to get the id from any of my domains, so i want to use a 
> variable:
>
> hosted_zone_name: "mydomain.com"
>
>
> and do something like:
>
> hosted_zone_id: "{{ dns_results | json_query('HostedZones[?Name==`{{ 
> hosted_zone_name 
> }}.`].[Id]') | regex_replace ('/hostedzone/', '') }}"
>
>
> But it looks like nested variables like that doesn't work...
>
> Any suggestions?
>
> Thanks!
>
> David
>
>
>

-- 
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/41087b73-c798-46ce-9b5a-6aae9ea673b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.