Re: [ansible-project] Ansible Split JSON Return

2020-03-06 Thread David Foley


On Thursday, March 5, 2020 at 8:48:12 PM UTC, Kai Stian Olstad wrote:
>
> On 05.03.2020 15:52, David Foley wrote: 
> > Have the Following Playbook Which Returns the following 
> > 
> > ok: [localhost] => { 
> > "mdb.json": [ 
>
> The [ is telling us that mdb.json is a list, the fist element in a list 
> i 0. 
>
> > { 
> > "mac-address": "xx:xx:xx:xx:xx" 
> > } 
> > ] 
> > } 
>
>  
>
> >   - debug: 
> >   msg: "{{ mdb.json.split(':') }}" 
> > 
> > What i would like to Return is just 
> > 
> >  "msg":  "xx:xx:xx:xx:xx" 
>
> That would be {{ mdb.json.0['mac-address'] }} 
>
> because of the dash in mac-address you need to use [] notation and not 
> the dot notation on that one. 
>
>
> -- 
> Kai Stian Olstad 
>

Thanks Kai,

that worked i was also able to Split('-')[0] and that only outputted the 
xxx:xxx:xxx:xx just what i was looking for.  

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6ada225d-044c-41d8-9def-a2add77d7b48%40googlegroups.com.


Re: [ansible-project] Ansible Split JSON Return

2020-03-05 Thread Kai Stian Olstad

On 05.03.2020 15:52, David Foley wrote:

Have the Following Playbook Which Returns the following

ok: [localhost] => {
"mdb.json": [


The [ is telling us that mdb.json is a list, the fist element in a list 
i 0.



{
"mac-address": "xx:xx:xx:xx:xx"
}
]
}





  - debug:
  msg: "{{ mdb.json.split(':') }}"

What i would like to Return is just

 "msg":  "xx:xx:xx:xx:xx"


That would be {{ mdb.json.0['mac-address'] }}

because of the dash in mac-address you need to use [] notation and not 
the dot notation on that one.



--
Kai Stian Olstad

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f3d3bf2f4bc46bb693a3d8c348cf3e4b%40olstad.com.


[ansible-project] Ansible Split JSON Return

2020-03-05 Thread David Foley
Have the Following Playbook Which Returns the following

ok: [localhost] => {
"mdb.json": [
{
"mac-address": "xx:xx:xx:xx:xx"
}
]
}


--
- hosts: localhost
  gather_facts: false
  tasks:
  - name: Getting Mac Address 
uri: url="http://.com?field=mac-address; return_content=yes
register: mdb
  - debug:
  msg: "{{ mdb.json.split(':') }}"

What i would like to Return is just 

 "msg":  "xx:xx:xx:xx:xx"

But Split doesn't seem to work 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/bbc6205a-89fe-452d-ad71-ef72a3714e0a%40googlegroups.com.