Thank you Dick Visser. I have added the json query in my playbook but It returned an error.
Can you please help me on this . ++++++++++++++++++++++++++ register: result - debug: msg="{{ result|json_query(jmesquery) }}" vars: jmesquery: "{{ result|json_query('configResolveDn.children[0].outConfig.children[0].equipmentPsu.attributes.{dn: dn, id: id, operability: operability, presence: presence}') }}" +++++++++++++++++++++++++++ PLAY [mdhd] ************************************************************************************************************************************** TASK [Checking PSU status] *********************************************************************************************************************** ok: [host] TASK [debug] ************************************************************************************************************************************* *fatal: [host]: FAILED! => {"msg": "Error in jmespath.search in json_query filter plugin:\nunhashable type: 'dict'"}* PLAY RECAP *************************************************************************************************************************************** host : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 +++++++++++++++++++++++++++++++++ Thank you, Ramesh On Sun, Dec 27, 2020 at 6:57 AM Dick Visser <dick.vis...@geant.org> wrote: > This will give you a list of just the values: > > "{{ > disk_output|json_query('configResolveDn.children[0].outConfig.children[0].equipmentPsu.attributes|[dn, > id, operability, presence]') }}" > > i.e.: > > - sys/rack-unit-1/psu-1 > - '1' > - operable > - equipped > > Something like this will yield a dict that contains keys as well: > > "{{ > disk_output|json_query('configResolveDn.children[0].outConfig.children[0].equipmentPsu.attributes.{dn: > dn, id: id, operability: operability, presence:presence}') }}" > > I.e.: > > dn: sys/rack-unit-1/psu-1 > id: '1' > operability: operable > presence: equipped > > > > On Thu, 24 Dec 2020 at 23:28, Ramesh AR <ramesh.a...@gmail.com> wrote: > > > > I'm very new to json query though I tried to get specific output but > couldn't get it .. it seems playbook runs good but no output. > > > > Can someone help me to get json query pls . > > > > ++++++++++++++++++++++++++++++++ > > json output: > > ok: [XXXXXX] => { > > "aaaLogin": { > > "attributes": { > > "cookie": "", > > "outCookie": > "1608848451/0e45e137-b73e-173e-9a2f-bc16ee6a0f70", > > "outPriv": "admin", > > "outRefreshPeriod": "600", > > "outSessionId": "6711", > > "outVersion": "3.1(3a)", > > "response": "yes" > > } > > }, > > "ansible_facts": { > > "discovered_interpreter_python": "/usr/bin/python3" > > }, > > "changed": false, > > "configResolveDn": { > > "attributes": { > > "cookie": "1608848451/0e45e137-b73e-173e-9a2f-bc16ee6a0f70", > > "dn": "sys/rack-unit-1/psu-1", > > "response": "yes" > > }, > > "children": [ > > { > > "outConfig": { > > "attributes": {}, > > "children": [ > > { > > "equipmentPsu": { > > "attributes": { > > "dn": "sys/rack-unit-1/psu-1", > > "fwVersion": "12002216", > > "id": "1", > > "input": "137", > > "maxOutput": "NA", > > "model": "700-014160-0000", > > "operability": "operable", > > "output": "124", > > "pid": "UCSC-PSU1-770W", > > "power": "on", > > "presence": "equipped", > > "serial": "ART2221F58Q", > > "thermal": "ok", > > "vendor": "Cisco Systems Inc", > > "voltage": "ok" > > } > > } > > } > > ] > > } > > } > > ] > > }, > > "elapsed": 4, > > "invocation": { > > "module_args": { > > "content": "<configResolveDn inHierarchical=\"false\" > dn=\"sys/rack-unit-1/psu-1\"/>\n", > > "hostname": "XXXXXX", > > "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", > > "path": null, > > "protocol": "https", > > "timeout": 60, > > "username": "VIPER_VIO", > > "validate_certs": false > > } > > }, > > "response": "OK (unknown bytes)", > > "status": 200 > > } > > > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > > > playbook set for specific query: ( Not working ) > > > > +++++++++++++++++++++++++++++++++++ > > register: psu_output > > - set_fact: > > psu: "{{ psu_output | json_query(query) }}" > > vars: > > query: "equipmentPsu.attributes[?operability=='operable']" > > ++++++++++++++++++++++++++++++++++++++ > > > > PLAY [md] > ************************************************************************************************************************************** > > > > TASK [Checking PSU status] > *********************************************************************************************************************** > > ok: [host1] > > > > TASK [set_fact] > ********************************************************************************************************************************** > > ok: [host1] > > > > PLAY RECAP > *************************************************************************************************************************************** > > host1 : ok=2 changed=0 unreachable=0 failed=0 > skipped=0 rescued=0 ignored=0 > > +++++++++++++++++++++++++++++++++++++++++++++ > > > > > > On Thu, Dec 24, 2020 at 2:00 AM Dick Visser <dick.vis...@geant.org> > wrote: > >> > >> That can be done with json_query: > >> > https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#selecting-json-data-json-queries > >> > >> On Wed, 23 Dec 2020 at 21:33, Ramesh AR <ramesh.a...@gmail.com> wrote: > >>> > >>> Yes, I'm able to get output now .thanks! .. But that seems to be a > very big and confusing ( what need to be looked ) > >>> > >>> anyone knows how to filter particular output from the below, > >>> > >>> Playbook, > >>> ++++++++++++++++++++++++++++++++++++++++++++ > >>> --- > >>> - hosts: somehost > >>> connection: local > >>> gather_facts: no > >>> vars_files: > >>> - /etc/ansible/var.yml > >>> tasks: > >>> - name: validate service accounts > >>> imc_rest: > >>> hostname: "{{ imc_hostname }}" > >>> username: "{{ imc_username }}" > >>> password: "{{ imc_password }}" > >>> protocol: https > >>> timeout: 60 > >>> validate_certs: no > >>> content: | > >>> <configResolveDn inHierarchical="false" > dn="sys/rack-unit-1/psu-1"/> > >>> register: disk_output > >>> - debug: > >>> msg: "{{ disk_output | to_nice_yaml }}" --- which tried to get > output > >>> > >>> ++++++++++++++++++++++++++++++++++++++++++++ > >>> TASK [debug] > ************************************************************************************************************************************* > >>> ok: [host1] => {} > >>> > >>> MSG: > >>> > >>> aaaLogin: > >>> attributes: > >>> cookie: '' > >>> outCookie: 1608754773/1b78d009-b728-1728-989f-bc16ee6a0f70 > >>> outPriv: admin > >>> outRefreshPeriod: '600' > >>> outSessionId: '6311' > >>> outVersion: 3.1(3a) > >>> response: 'yes' > >>> ansible_facts: > >>> discovered_interpreter_python: /usr/bin/python3 > >>> changed: false > >>> configResolveDn: > >>> attributes: > >>> cookie: 1608754773/1b78d009-b728-1728-989f-bc16ee6a0f70 > >>> dn: sys/rack-unit-1/psu-1 > >>> response: 'yes' > >>> children: > >>> - outConfig: > >>> attributes: {} > >>> children: > >>> - equipmentPsu: > >>> attributes: > >>> dn: sys/rack-unit-1/psu-1 > >>> fwVersion: '12002216' > >>> id: '1' > >>> input: '137' > >>> maxOutput: NA > >>> model: 700-014160-0000 > >>> operability: operable > >>> output: '125' > >>> pid: UCSC-PSU1-770W > >>> power: 'on' > >>> presence: equipped > >>> serial: ART2221F58Q > >>> thermal: ok > >>> vendor: Cisco Systems Inc > >>> voltage: ok > >>> elapsed: 4 > >>> failed: false > >>> response: OK (unknown bytes) > >>> status: 200 > >>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > >>> > >>> I want to filter only below, > >>> > >>> ['dn: sys/rack-unit-1/psu-1' 'id: '1', 'operability: operable' , > 'presence: equipped'] > >>> > >>> > >>> On Wednesday, 23 December 2020 at 04:10:05 UTC-5 dick....@geant.org > wrote: > >>>> > >>>> On Tue, 22 Dec 2020 at 22:23, Ramesh AR <rames...@gmail.com> wrote: > >>>> > > >>>> > > >>>> > I already tried to set register and debug but got the below error. > >>>> > > >>>> > "msg": "Unsupported parameters for (imc_rest) module: register > Supported parameters include: content, hostname, password, path, protocol, > timeout, username, validate_certs > >>>> > >>>> This is because your indentation is incorrect, so fix that. > >>>> > >>>> > >>>> -- > >>>> Dick Visser > >>>> Trust & Identity Service Operations Manager > >>>> GÉANT > >>> > >>> -- > >>> 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/1684614b-6d33-42a1-9d78-05a431a4e02fn%40googlegroups.com > . > >> > >> -- > >> Sent from a mobile device - please excuse the brevity, spelling and > punctuation. > >> > >> -- > >> You received this message because you are subscribed to a topic in the > Google Groups "Ansible Project" group. > >> To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/AciMXagbLCo/unsubscribe. > >> To unsubscribe from this group and all its topics, 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/CAL8fbwPSnWZFp1QOEVQeu9fF41gcOa7GvtzQOup0r1-RZHDKoQ%40mail.gmail.com > . > > > > > > > > -- > > Regards, > > > > Ramesh > > > > -- > > 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/CAKefOJrdE%2BJfW_7gZdqPFx9x9EPCzsMaR%2BRCVrqXNAn91s%3DoOQ%40mail.gmail.com > . > > > > -- > Dick Visser > Trust & Identity Service Operations Manager > GÉANT > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ansible Project" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/AciMXagbLCo/unsubscribe. > To unsubscribe from this group and all its topics, 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/CAL8fbwNYgObJ%3DEEbK1Xx2JPd%2BB6k%2BNjRaZQGV4atkDCcHP5N4w%40mail.gmail.com > . > -- Regards, Ramesh -- 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/CAKefOJpO-4LKNmuSf%3DXS5hWCXXipDk_6tgwkTBd5MWxVEnMv1Q%40mail.gmail.com.