Re: [ansible-devel] mapping json variable to list using set_fact

2019-10-11 Thread Balasubramaniam M
Many thanks for the response:

 I have one more array within imdata. COuld you please guide me how to 
extract fields? it is somewhat like

 new_var: "{{ your_var | 
json_query('nodes.imdata[*].result[*].fabricNode.attributes.{dn:dn,name:name}') 
}}"


also in could you please tell me mention that? just variable or upto array

I appreciate  your help

thanks

On Friday, October 11, 2019 at 7:35:17 PM UTC+5:30, Chris Church wrote:
>
> The json_query filter is probably what you're looking for:
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#json-query-filter
>
> - set_fact:
> new_var: "{{ your_var | 
> json_query('nodes.imdata[*].fabricNode.attributes.{dn:dn,name:name}') }}"
>
> should give you:
>
> [
>   {
> "dn": "topology/pod-1/node-1",
> "name": "NOQCJALAB1"
>   },
>   {
> "dn": "topology/pod-1/node-1",
> "name": "NOQCJALAB2"
>   }
> ]
>
>
> On Fri, Oct 11, 2019 at 3:09 AM Balasubramaniam M  > wrote:
>
>> Hello All,
>>
>> I have register variable with below json as value and need to extract 
>> name and dn from this JSON to list. tried different options using set_fact 
>> without any luck. Could you please someone help? this is really urgent
>>
>> {
>> "nodes": {
>> "status": -1,
>> "imdata": [
>> {
>> "fabricNode": {
>> "attributes": {
>> "status": "",
>> "dn": "topology/pod-1/node-1",
>> "name": "NOQCJALAB1"
>> }
>> }
>> },
>> {
>> "fabricNode": {
>> "attributes": {
>> "status": "",
>> "dn": "topology/pod-1/node-1",
>> "name": "NOQCJALAB2"
>> }
>> }
>> }
>> ],
>> "totalCount": 2,
>> "changed": false,
>> "failed": false
>> },
>> "changed": false,
>> "_ansible_verbose_always": true,
>> "_ansible_no_log": false
>> }
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to ansibl...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-devel/72ef3632-4fd3-4f9b-9a1f-6901202cca33%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> --
> Chris Church
> flyin...@gmail.com 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/0c9b7989-cada-4e2e-8695-82916d6178e7%40googlegroups.com.


Re: [ansible-devel] mapping json variable to list using set_fact

2019-10-11 Thread Chris Church
The json_query filter is probably what you're looking for:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#json-query-filter

- set_fact:
new_var: "{{ your_var |
json_query('nodes.imdata[*].fabricNode.attributes.{dn:dn,name:name}')
}}"

should give you:

[
  {
"dn": "topology/pod-1/node-1",
"name": "NOQCJALAB1"
  },
  {
"dn": "topology/pod-1/node-1",
"name": "NOQCJALAB2"
  }
]


On Fri, Oct 11, 2019 at 3:09 AM Balasubramaniam M 
wrote:

> Hello All,
>
> I have register variable with below json as value and need to extract name
> and dn from this JSON to list. tried different options using set_fact
> without any luck. Could you please someone help? this is really urgent
>
> {
> "nodes": {
> "status": -1,
> "imdata": [
> {
> "fabricNode": {
> "attributes": {
> "status": "",
> "dn": "topology/pod-1/node-1",
> "name": "NOQCJALAB1"
> }
> }
> },
> {
> "fabricNode": {
> "attributes": {
> "status": "",
> "dn": "topology/pod-1/node-1",
> "name": "NOQCJALAB2"
> }
> }
> }
> ],
> "totalCount": 2,
> "changed": false,
> "failed": false
> },
> "changed": false,
> "_ansible_verbose_always": true,
> "_ansible_no_log": false
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-devel/72ef3632-4fd3-4f9b-9a1f-6901202cca33%40googlegroups.com
> 
> .
>


-- 
--
Chris Church
flyingfr...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/CAH%2BKTJ5%2B9pbrNgu0PkHXV3YLFVk2RLveJ6%3DHM3549x%3DxVDARdQ%40mail.gmail.com.


[ansible-devel] mapping json variable to list using set_fact

2019-10-11 Thread Balasubramaniam M
Hello All,

I have register variable with below json as value and need to extract name 
and dn from this JSON to list. tried different options using set_fact 
without any luck. Could you please someone help? this is really urgent

{
"nodes": {
"status": -1,
"imdata": [
{
"fabricNode": {
"attributes": {
"status": "",
"dn": "topology/pod-1/node-1",
"name": "NOQCJALAB1"
}
}
},
{
"fabricNode": {
"attributes": {
"status": "",
"dn": "topology/pod-1/node-1",
"name": "NOQCJALAB2"
}
}
}
],
"totalCount": 2,
"changed": false,
"failed": false
},
"changed": false,
"_ansible_verbose_always": true,
"_ansible_no_log": false
}

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/72ef3632-4fd3-4f9b-9a1f-6901202cca33%40googlegroups.com.