Experts help need for imc_rest module

33 views
Skip to first unread message

rames...@gmail.com

unread,
Dec 21, 2020, 2:04:30 PM12/21/20
to Ansible Project
Hi Folks,

Does anyone had an experience to use imc_rest module ? I'm trying to get information or output about hardware inventory . Say for example, I have equipmentPsu to check PSU status. however, the output is not showing when I run my playbook. is there a way to filter the attributes?

My playbook:
---
- hosts: mdhd
  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: |
          <configResolveClass inHierarchical="false" classId="equipmentPsu"/>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
output:

PLAY [mdhd] **************************************************************************************************************************************

TASK [validate PSUs] *****************************************************************************************************************
ok: [10.138.67.30]

PLAY RECAP ***************************************************************************************************************************************
10.138.67.30               : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
++++++++++++++++++++++++++++++++++++++++++++++++++++
When I check -vvv , seeing the below output. 
  
   "equipmentPsu": {
                                "attributes": {
                                    "dn": "sys/rack-unit-1/psu-1",
                                    "fwVersion": "12002216",
                                    "id": "1",
                                    "input": "80",
                                    "maxOutput": "NA",
                                    "model": "700-014160-0000",
                                    "operability": "operable",
                                    "output": "65",
                                    "pid": "UCSC-PSU1-770W",
                                    "power": "on",
                                    "presence": "equipped",
                                    "serial": "ART2221F4WG",
                                    "thermal": "ok",
                                    "vendor": "Cisco Systems Inc",
                                    "voltage": "ok"
                                }
                            }
                        },
                        {
                            "equipmentPsu": {
                                "attributes": {
                                    "dn": "sys/rack-unit-1/psu-2",
                                    "fwVersion": "12002216",
                                    "id": "2",
                                    "input": "73",
                                    "maxOutput": "NA",
                                    "model": "700-014160-0000",
                                    "operability": "operable",
                                    "output": "60",
                                    "pid": "UCSC-PSU1-770W",
                                    "power": "on",
                                    "presence": "equipped",
                                    "serial": "ART2221F4XN",
                                    "thermal": "ok",
                                    "vendor": "Cisco Systems Inc",
                                    "voltage": "ok"
                                }
++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Thanks,
Ramesh

Dick Visser

unread,
Dec 22, 2020, 12:15:49 AM12/22/20
to ansible...@googlegroups.com
I think you need to register the result of this module and then to some operation on it. 
Such as debug to display it. 
This is not specific to the imc_rest module:


--
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/1cbb3d8e-d40a-44a7-8174-7775a7fcc694n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Ramesh AR

unread,
Dec 22, 2020, 4:23:19 PM12/22/20
to Ansible Project

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

Thanks,
Ramesh

Dick Visser

unread,
Dec 23, 2020, 4:10:05 AM12/23/20
to ansible...@googlegroups.com
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

Ramesh AR

unread,
Dec 23, 2020, 3:32:51 PM12/23/20
to Ansible Project
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']

Dick Visser

unread,
Dec 24, 2020, 2:00:10 AM12/24/20
to ansible...@googlegroups.com

--
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.

Ramesh AR

unread,
Dec 24, 2020, 5:28:10 PM12/24/20
to ansible...@googlegroups.com
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
+++++++++++++++++++++++++++++++++++++++++++++


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-proje...@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 

Dick Visser

unread,
Dec 27, 2020, 6:57:18 AM12/27/20
to ansible...@googlegroups.com
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
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKefOJrdE%2BJfW_7gZdqPFx9x9EPCzsMaR%2BRCVrqXNAn91s%3DoOQ%40mail.gmail.com.

Ramesh AR

unread,
Dec 28, 2020, 3:03:19 PM12/28/20
to ansible...@googlegroups.com
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


Dick Visser

unread,
Dec 28, 2020, 5:02:48 PM12/28/20
to ansible...@googlegroups.com
On Mon, 28 Dec 2020 at 21:03, Ramesh AR <rames...@gmail.com> wrote:
>
> 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}') }}"
> +++++++++++++++++++++++++++

You're mixing up things, by using a vars argument that includes the
entire json_query filter itself, and then doing json_query on that,
which fails.
Either use a vars argument correctly, or don't use it at all.
See the examples on
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#selecting-json-data-json-queries.
I would only use a vars argument if the query contains variables
itself, or lots of backticks etc.
This case does not warrant that.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKefOJpO-4LKNmuSf%3DXS5hWCXXipDk_6tgwkTBd5MWxVEnMv1Q%40mail.gmail.com.

Ramesh AR

unread,
Dec 28, 2020, 6:21:36 PM12/28/20
to ansible...@googlegroups.com
Understood.. Thanks.  my bad it was very simple .

TASK [Display PSU status] ************************************************************************************************************************
ok: [host1] => {
    "msg": {
        "dn": "sys/rack-unit-1/psu-1",


--
Regards,

Ramesh 
Reply all
Reply to author
Forward
0 new messages