Automatically putting value in bracket []

45 views
Skip to first unread message

Pravin V

unread,
Nov 10, 2020, 8:13:53 AM11/10/20
to Ansible Project
Hello Everyone,
Below is the output of the task
json:
      resourceIds:
      - 66523

and I'm trying to fetch the resourceIDs into the task like below.
RESOURCEID_LIST={{ resourceID.json.resourceIds }}

But the issue is when I'm running the playbook, it is automatically putting the value in bracket []
&RESOURCEID_LIST=[66523].

How can we input the value without putting in the bracket.

Thanks in advance.

Dick Visser

unread,
Nov 10, 2020, 8:33:21 AM11/10/20
to ansible...@googlegroups.com
Brackets is the correct way to display lists variables, which your variable apparently is.



--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/42cc9fff-b3fe-4584-bb0f-bdd580647822n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Pravin V

unread,
Nov 10, 2020, 8:40:59 AM11/10/20
to Ansible Project
Thank you, Dick.

Here's the issue, I'm trying to automate device adding using Rest API, it will accept the command as below -

Whereas in current situation it is automatically putting the value in the bracket as below -
url: http://5.5.5.5/api/json/ncmsettings/assocCredential?apiKey= xx6689kk &RESOURCEID_LIST=[4204]&SSH_PROFILELIST=ABC&protocolCombinationList=SSH
This way it is not working.

Please suggest what can we do in this situation.

Stefan Hornburg (Racke)

unread,
Nov 10, 2020, 8:48:54 AM11/10/20
to ansible...@googlegroups.com
On 11/10/20 2:40 PM, Pravin V wrote:
> Thank you, Dick.
>
> Here's the issue, I'm trying to automate device adding using Rest API, it will accept the command as below -
> url:
> http://5.5.5.5/api/json/ncmsettings/assocCredential?apiKey=xx6689kk&RESOURCEID_LIST=4204&SSH_PROFILELIST=ABC&protocolCombinationList=SSH
>
> Whereas in current situation it is automatically putting the value in the bracket as below -
> url: http://5.5.5.5/api/json/ncmsettings/assocCredential?apiKey=
> xx6689kk &RESOURCEID_LIST=[4204]&SSH_PROFILELIST=ABC&protocolCombinationList=SSH
> This way it is not working.
>
> Please suggest what can we do in this situation.

If it is always a single value use the first element of the list:

RESOURCEID_LIST={{ resourceID.json.resourceIds[0] }}

Regards
Racke

>
>
> On Tuesday, 10 November 2020 at 19:03:21 UTC+5:30 dick....@geant.org wrote:
>
> Brackets is the correct way to display lists variables, which your variable apparently is.
>
>
>
> On Tue, 10 Nov 2020 at 14:14, Pravin V <pravee...@gmail.com> wrote:
>
> Hello Everyone,
> Below is the output of the task
> json:
>       resourceIds:
>       - 66523
>
> and I'm trying to fetch the resourceIDs into the task like below.
> RESOURCEID_LIST={{ resourceID.json.resourceIds }}
>
> But the issue is when I'm running the playbook, it is automatically putting the value in bracket []
> &RESOURCEID_LIST=[66523].
>
> How can we input the value without putting in the bracket.
>
> Thanks in advance.
>
> --
> 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-proje...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/42cc9fff-b3fe-4584-bb0f-bdd580647822n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/42cc9fff-b3fe-4584-bb0f-bdd580647822n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> Sent from a mobile device - please excuse the brevity, spelling and punctuation.
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a0b92b62-6e44-497e-86d1-0427fb2d1316n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/a0b92b62-6e44-497e-86d1-0427fb2d1316n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.
OpenPGP_0x5B93015BFA2720F8.asc
OpenPGP_signature

Pravin V

unread,
Nov 10, 2020, 8:50:23 AM11/10/20
to Ansible Project
Thank you, Dick.

Here's the issue, I'm trying to automate device adding using Rest API, it will accept the command as below -

Whereas in current situation it is automatically putting the value in the bracket as below -
url: http://5.5.5.5/api/json/ncmsettings/assocCredential?apiKey= xx6689kk &RESOURCEID_LIST=[4204]&SSH_PROFILELIST=ABC&protocolCombinationList=SSH
This way it is not working.

Like we have one filter - ipaddr, which converts the value without network like below
to
3.3.3.3.
I was able to achieve the result using the below command -
{{ result.primary_ip4.address | ipaddr ('address') }}


Please suggest what can we do in this situation. 

Thanks, 

Pravin V

unread,
Nov 10, 2020, 4:08:02 PM11/10/20
to Ansible Project
Thank you. That's how I was using it, just thought to check if we have better option.  
Reply all
Reply to author
Forward
0 new messages