I run a task that captures the status of an interface for multiple devices and in some cases for more than one interface but I can only retrieve one stdout_lines at a time but I need to retrieve all of the stdout_lines for the hosts it runs the command on. I have the task code to access a respective stdout_lines of the list but not all of them.
- name: Execute IOS command to check port state up/down before configuration
ios_command:
commands:
- "show ip int brief | in {{item}}"
loop: "{{ports}}"
register: PortUpDown
- name: print port state up/down
debug:
#msg: "{{item.0 | to_nice_yaml}}"
#msg: "{{item.1 | to_nice_yaml}}"
msg: "{{item}}"
loop:
#- "{{PortUpDown.results.0.stdout_lines}}"
#- "{{PortUpDown.results.1.stdout_lines}}"
- "{{PortUpDown.results}}"
register: PortUpDown
- name: print var that capture port state up/down
debug:
var: PortUpDown
As you can see I have commented the items I was accessing during the testing. What I ultimately want is to be able to access 0,1,2,3 etc without the need to declare it because at the start of the script I will not know if it's just going to be one interface or multiple interfaces in the list that I'm going to get the port state.
The output is this.
ok: [hub1] => {
"PortUpDown": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"item": [
{
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet1/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet1/1",
"stdout": [
"Ethernet1/1 unassigned YES NVRAM up up"
],
"stdout_lines": [
[
"Ethernet1/1 unassigned YES NVRAM up up"
]
]
},
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet2/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet2/1",
"stdout": [
"Ethernet2/1 unassigned YES NVRAM administratively down down"
],
"stdout_lines": [
[
"Ethernet2/1 unassigned YES NVRAM administratively down down"
]
]
}
],
"msg": [
{
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet1/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet1/1",
"stdout": [
"Ethernet1/1 unassigned YES NVRAM up up"
],
"stdout_lines": [
[
"Ethernet1/1 unassigned YES NVRAM up up"
]
]
},
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet2/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet2/1",
"stdout": [
"Ethernet2/1 unassigned YES NVRAM administratively down down"
],
"stdout_lines": [
[
"Ethernet2/1 unassigned YES NVRAM administratively down down"
]
]
}
]
}
]
}
}
ok: [hub2] => {
"PortUpDown": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"item": [
{
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet1/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet1/1",
"stdout": [
"Ethernet1/1 unassigned YES NVRAM up up"
],
"stdout_lines": [
[
"Ethernet1/1 unassigned YES NVRAM up up"
]
]
},
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet2/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet2/1",
"stdout": [
"Ethernet2/1 unassigned YES NVRAM administratively down down"
],
"stdout_lines": [
[
"Ethernet2/1 unassigned YES NVRAM administratively down down"
]
]
}
],
"msg": [
{
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet1/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet1/1",
"stdout": [
"Ethernet1/1 unassigned YES NVRAM up up"
],
"stdout_lines": [
[
"Ethernet1/1 unassigned YES NVRAM up up"
]
]
},
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": null,
"commands": [
"show ip int brief | in Ethernet2/1"
],
"host": null,
"interval": 1,
"match": "all",
"password": null,
"port": null,
"provider": null,
"retries": 10,
"ssh_keyfile": null,
"timeout": null,
"username": null,
"wait_for": null
}
},
"item": "Ethernet2/1",
"stdout": [
"Ethernet2/1 unassigned YES NVRAM administratively down down"
],
"stdout_lines": [
[
"Ethernet2/1 unassigned YES NVRAM administratively down down"
]
]
}
]
}
]
}
}