[ansible-project] Re: Ansible Split JSON Return

2020-03-05 Thread Cade Lambert
Ok, try this then:

- debug:
  msg: "{{ item.mac-address }}"
  loop: "{{ mdb.json }}"

On Thursday, March 5, 2020 at 10:45:03 AM UTC-5, David Foley wrote:
>
> -
> - hosts: localhost
>   gather_facts: false
>   tasks:
>   - name: Getting Mac Address 
> uri: 
>   url: http://.com 
>   return_content: yes
>
> register: mdb
>   - debug:
>   msg: "{{ mdb.json }}"
>
>
>

-- 
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/0fcc3dce-712d-45df-a1d4-95c3848493db%40googlegroups.com.


[ansible-project] Re: Ansible Split JSON Return

2020-03-05 Thread David Foley
-
- hosts: localhost
  gather_facts: false
  tasks:
  - name: Getting Mac Address 
uri: 
  url: http://.com 
  return_content: yes

register: mdb
  - debug:
  msg: "{{ mdb.json }}"


-- 
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/c598fea5-0c18-44b4-a72e-8ffa20d402c8%40googlegroups.com.


[ansible-project] Re: Ansible Split JSON Return

2020-03-05 Thread Cade Lambert
What's your plabook look like? You'll probably have to loop through your 
JSON results as it looks like it's a list.

On Thursday, March 5, 2020 at 10:34:40 AM UTC-5, David Foley wrote:
>
> When i do Both 
>
> "{{ mdb.json.mac-address }}"
> "{{ mdb.json.split(':')[1:6] | join(':') }}"
>
> It returns 
>
> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with 
> an undefined variable. The error was: 'list object' has no attribute 
> 'mac'\n\nThe error appears to be in '/srv/Ansible/mdb.yaml': line 8, column 
> 5, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\nregister: mdb\n  - 
> debug:\n^ here\n"}
>
> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with 
> an undefined variable. The error was: 'list object' has no attribute 
> 'split'\n\nThe error appears to be in '/srv/Ansible/mdb.yaml': line 8, 
> column 5, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\nregister: mdb\n  - 
> debug:\n^ here\n"}
>
>
>

-- 
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/7aa61efa-1cf0-4604-9b7a-bd30d6349c9f%40googlegroups.com.


[ansible-project] Re: Ansible Split JSON Return

2020-03-05 Thread David Foley
When i do Both 

"{{ mdb.json.mac-address }}"
"{{ mdb.json.split(':')[1:6] | join(':') }}"

It returns 

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 'list object' has no attribute 
'mac'\n\nThe error appears to be in '/srv/Ansible/mdb.yaml': line 8, column 
5, but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\nregister: mdb\n  - 
debug:\n^ here\n"}

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 'list object' has no attribute 
'split'\n\nThe error appears to be in '/srv/Ansible/mdb.yaml': line 8, 
column 5, but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\nregister: mdb\n  - 
debug:\n^ here\n"}


-- 
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/a32f963e-ae87-45ac-b930-0fbd78e46de6%40googlegroups.com.


[ansible-project] Re: Ansible Split JSON Return

2020-03-05 Thread Cade Lambert
Something like this would work I believe:

"{{ mdb.json.split(':')[1:6] | join(':') }}"

Also, could you not just reference it directly by using "{{ 
mdb.json.mac-address }}"?

On Thursday, March 5, 2020 at 9:52:52 AM UTC-5, David Foley wrote:
>
> 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/0776c9b4-d5fd-439c-bdb9-ac1ef03425db%40googlegroups.com.