Open Source Development

Power Open Source Development

Explore the open source tools and capabilities for building and deploying modern applications on IBM Power platforms including AIX, IBM i, and Linux.


#Power


#Power

 View Only
  • 1.  Retrieving an attribute from Ansible module ibm.power_aix.nim

    Posted Tue November 08, 2022 08:50 AM
    I'm trying to retrieve the location attribute from an lpp_source resource using Ansible.

    I use the following in my playbook:

      - name: Retrieve the mounted lpp_source directory path
        ibm.power_aix.nim:
          action: show
          object_type: lpp_source
        register: lpp_resources
    lpp_resources has the following:

    ok: [nim01] => {
    "lpp_resources": {
                 "changed": false,
    "cmd": "lsnim -l -Z -t lpp_source",
    "failed": false,
    "meta": {
    "messages": [],
    "query": {
    "7200-05-01-lpp": {
    "Rstate": "ready for use",
    "alloc_count": "0",
    "arch": "power",
    "class": "resources",
    "location": "/export/nim/lpp_source/7200-05-0_1lpp_res",
    "nfs_sec": "sys",
    "nfs_vers": "4",
    "prev_state": "unavailable for use",
    "server": "master",
    "simages": "yes",
    "type": "lpp_source"
    },
    "7200-05-03-lpp": {
    "Rstate": "ready for use",
    "alloc_count": "0",
    "arch": "power",
    "class": "resources",
    "location": "/export/nim/lpp_source/7200-05-03-lpp_res",
    "prev_state": "unavailable for use",
    "server": "master",
    "simages": "yes",
    "type": "lpp_source"
    },
    "7200-05-04-2220-lpp_source": {
    "": "",
    "Rstate": "ready for use",
    "alloc_count": "1",
    "arch": "power",
    "class": "resources",
    "comments": "\"Updates from 7200-05 to 7200-05-04-2220, built by Ansible Aix Automate infrastructure updates tools\"",
    "location": "/export/nim/lpp_source/7200-05-04-2220-lpp_source",
    "prev_state": "unavailable for use",
    "server": "master",
    "type": "lpp_source"
    }
    }
    },
    "msg": "NIM show operation successful. See status and meta for details.",
    "nim_node": {},
    "rc": 0,
    "status": {},
    "stderr": "",
    "stderr_lines": [],
    "stdout": "see meta.query",
    "stdout_lines": [
    "see meta.query"
    ]
    }
    }


    I want to retrieve the location from the third lpp_source.

    I've tried loop and with_Items and I can get all three lpp_source entries in to a variable but I can't work out how to get location from the third entry.







    ------------------------------
    Glenn Robinson
    ------------------------------

    #AIXOpenSource


  • 2.  RE: Retrieving an attribute from Ansible module ibm.power_aix.nim

    Posted Tue November 08, 2022 01:11 PM
    So, that's a nested dictionary. The best way to handle that is with a json_query, but I'm unable to get that working in my environment for a host of reasons.

    Barring that, the other solution is to loop through the nest and cherry pick the items you want.

    - name: Retrieve the mounted lpp_source directory path 
        ibm.power_aix.nim:
          action: show
          object_type: lpp_source
        register: lpp_resources
    
    - name: show the value we want
      debug:
        msg: "{{ item.key }}{{ item.value.location }}"
      with_dict: "{{ lpp_resources.meta.query }}"
      when: item.key == "7200-05-04-2220-lpp_source"​

    Now, you asked to pull the nth item from the list. You could this, but keep in mind there's no guarantee on list order.

    - name: Retrieve the mounted lpp_source directory path 
        ibm.power_aix.nim:
          action: show
          object_type: lpp_source
        register: lpp_resources
    
    - name: show the value we want
      debug:
        msg: "{{ item.key }}{{ item.value.location }}"
      with_dict: "{{ lpp_resources.meta.query }}"
      loop_control:
        extended: true
      when: ansible_loop.index == 3​


    ------------------------------
    Mario Stargard
    ------------------------------



  • 3.  RE: Retrieving an attribute from Ansible module ibm.power_aix.nim

    Posted Wed November 09, 2022 12:10 AM
    Perfect. It was my lack of understanding of the nested dictionary causing me a problem.

    After some reading up following your response I'm clearer on this.

    Thank you.

    ------------------------------
    Glenn Robinson
    ------------------------------