On 9/24/20 3:46 PM, Devops testing wrote:
> play:
> - set_fact:
> irules: "{{ rule | json_query('[*].definition') }}"
> - debug: msg: "{{ irules }}"
>
> output:
> "msg": [ "when HTTP_REQUEST {\n switch -glob [HTTP::uri] {\n \"*HAC*\" { pool char.hr.cal.ed.ABC.pool }\n
> \n } \n}" ]
>
> I'm expecting output to be in below format.
>
> *Expected output:*
> "when HTTP_REQUEST {
> switch -glob [HTTP::uri] {
> "*HAC*" { pool char.hr.cal.ed.ABC.pool }
> }"
>
>
> I have tried parsing "*from_json"* to the above play and ended up with the error:
> "({{ rule | json_query('[*].definition') | from_json }}): the JSON object must be str, bytes or ``bytearray, not 'list'"}"
>
> is there a way to convert list to string in ansibe? if not, any other suggestions would be appreciated to achieve
> "Expected output"`
As a json_query can have multiple results, the result of that filter is a list.
To get the first result you can use irules[0] or irules | first.
Regards
Racke
>
>
>
> --
> 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/79aca988-710a-4671-b967-a70d55052871n%40googlegroups.com
> <
https://groups.google.com/d/msgid/ansible-project/79aca988-710a-4671-b967-a70d55052871n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.