Output of the debug: msg: Module

Hi everyone,
I am pretty new to Ansible, and actualy I write different playbooks to automate tasks in a Cisco ACI Fabric. It works great but I stumble over some Problems here and there.

So just a quick question. I try to extract basic Switch Infos from my APIC with a playbook like this

  • name: ACI_add_fabric_nodes
    hosts: ACI_Simulator
    gather_facts: False
    connection: local
    vars:
    ansible_command_timeout: 500

    tasks:

    • name: Query fabric nodes
      cisco.aci.aci_fabric_node:
      host: “{{ host }}”
      validate_certs: False
      username: “{{ user }}”
      password: “{{ password }}”
      state: query
      delegate_to: localhost
      register: query_result

    • name: Active Nodes
      debug:
      msg: “Switch: {{ item.fabricNodeIdentP.attributes.name }}, Role: {{ item.fabricNodeIdentP.attributes.role }}, POD: {{ item.fabricNodeIdentP.attributes.podId }}, Seriennummer: {{ item.fabricNodeIdentP.attributes.serial }}”
      loop: “{{ query_result.current }}”

the output I get is

TASK [Active Nodes] ***************************************************************************************************************************************************************************************************************************************************************************************
ok: [aci-sim] => (item={‘fabricNodeIdentP’: {‘attributes’: {‘annotation’: ‘orchestrator:ansible’, ‘childAction’: ‘’, ‘descr’: ‘’, ‘dn’: ‘uni/controller/nodeidentpol/nodep-TEP-1-101’, ‘extMngdBy’: ‘’, ‘extPoolId’: ‘0’, ‘fabricId’: ‘1’, ‘lcOwn’: ‘local’, ‘modTs’: ‘2023-11-23T09:03:38.399+00:00’, ‘monPolDn’: ‘uni/fabric/monfab-default’, ‘name’: ‘msgleaf1001i’, ‘nameAlias’: ‘’, ‘nodeId’: ‘1001’, ‘nodeType’: ‘unspecified’, ‘podId’: ‘1’, ‘role’: ‘leaf’, ‘serial’: ‘TEP-1-101’, ‘status’: ‘’, ‘uid’: ‘15374’, ‘userdom’: ‘:all:’}}}) => {
“msg”: “Switch: msgleaf1001i, Role: leaf, POD: 1, Seriennummer: TEP-1-101”
}
ok: [aci-sim] => (item={‘fabricNodeIdentP’: {‘attributes’: {‘annotation’: ‘orchestrator:ansible’, ‘childAction’: ‘’, ‘descr’: ‘’, ‘dn’: ‘uni/controller/nodeidentpol/nodep-TEP-1-102’, ‘extMngdBy’: ‘’, ‘extPoolId’: ‘0’, ‘fabricId’: ‘1’, ‘lcOwn’: ‘local’, ‘modTs’: ‘2023-11-23T09:03:53.423+00:00’, ‘monPolDn’: ‘uni/fabric/monfab-default’, ‘name’: ‘msgleaf1002i’, ‘nameAlias’: ‘’, ‘nodeId’: ‘1002’, ‘nodeType’: ‘unspecified’, ‘podId’: ‘1’, ‘role’: ‘leaf’, ‘serial’: ‘TEP-1-102’, ‘status’: ‘’, ‘uid’: ‘15374’, ‘userdom’: ‘:all:’}}}) => {
“msg”: “Switch: msgleaf1002i, Role: leaf, POD: 1, Seriennummer: TEP-1-102”
}
ok: [aci-sim] => (item={‘fabricNodeIdentP’: {‘attributes’: {‘annotation’: ‘orchestrator:ansible’, ‘childAction’: ‘’, ‘descr’: ‘’, ‘dn’: ‘uni/controller/nodeidentpol/nodep-TEP-1-103’, ‘extMngdBy’: ‘’, ‘extPoolId’: ‘0’, ‘fabricId’: ‘1’, ‘lcOwn’: ‘local’, ‘modTs’: ‘2023-11-23T09:03:54.557+00:00’, ‘monPolDn’: ‘uni/fabric/monfab-default’, ‘name’: ‘msgspine101i’, ‘nameAlias’: ‘’, ‘nodeId’: ‘101’, ‘nodeType’: ‘unspecified’, ‘podId’: ‘1’, ‘role’: ‘spine’, ‘serial’: ‘TEP-1-103’, ‘status’: ‘’, ‘uid’: ‘15374’, ‘userdom’: ‘:all:’}}}) => {
“msg”: “Switch: msgspine101i, Role: spine, POD: 1, Seriennummer: TEP-1-103”
}
is it possible to just get the msg Part, like:

“msg”: “Switch: msgleaf1001i, Role: leaf, POD: 1, Seriennummer: TEP-1-101”
“msg”: “Switch: msgleaf1002i, Role: leaf, POD: 1, Seriennummer: TEP-1-102”
“msg”: “Switch: msgspine101i, Role: spine, POD: 1, Seriennummer: TEP-1-103”

Thank you very much!

Welcome to the forum! I don’t have time for a longer answer, but here’s a first pointer that will already improve the output a lot: Loops — Ansible Documentation

2 Likes

Hi,

is it possible to just get the msg Part

Yes, you could use loop_control with label key.

1 Like

thank you very much, that did indeed the trick. haha I have a lot to learn, the Journey begins

1 Like