Hi Jimmy,
I think that if you do:
- name: set the fact
set_fact:
keyobject: "{{ registerVar|from_json }}"
You should then be able to do keyobject[key]. The "complex arguments" form
works because Ansible (for reasons I am not fully understanding) will
preserve the data structure when passed this way, but not using the
all-in-one-line form with the equals signs.
Hope this helps!
-Tim
On Sun, Dec 14, 2014 at 2:54 PM, <[email protected]> wrote:
>
> I am going to keep this post short and sweet and hope someone can help me
> wrap my head around how to grab values from key,value pairs returned by a
> script I an running.
>
> I use the ansible "shell:" module to run a script that generates and API
> key and ID and prints the results to stdout and then I use register to save
> the data.
>
> Lets say I use register: or set_fact: to save the results of the following
> command to 'keyobject':
>
> ./script generatekey bar --bw --obj
> {
> "app": "bar",
> "id": "3aa234234dfadsf2348351",
> "key": "aeb46dasdfasdfcc9c5e2b031edsdddd2e56c33c7d61efbb071fb06"
> }
>
> When I attempt to do a simple debug: msg="{{ keyobject" }} it will print
> everything out no problem (with some extra stuff added). But if I try
> something like {{ keyobject['key'] }} or keyobject.key or any other
> multitude of variations on that I am not having much success. It seems the
> json gets mangled or extra info added like 'msg'.
>
> I am too worn out now to post all of the different things I have tried and
> their resulting failures. I've gotten close but not further than close. If
> this isn't possible let me know and I will stop torturing myself.
>
> Based on the above output what would you try? I've also tried from_json
> and some other things. I was certain I would have this pegged within a few
> hours but after reading a million posts and trying to figure it out
> unsuccessfully with a co-worker I am feeling defeated :)
>
> Thanks!
>
> --
> 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/061a2beb-82a6-4553-8b21-28c1332fefed%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/061a2beb-82a6-4553-8b21-28c1332fefed%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/CAH4wdVU8jVOQ%2B0%2BuevCr%3D5KTOrxrfnjtvGo3hOy_9X4%2BHqu4dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.