how can I pull a string from the stdout and use it for failed_when? I run a command on a switch and then I want to match a string w/in that output to determine if it failed or not.
---
- name: Check the ssh keypair on a Nexus 9k
hosts: all
gather_facts: false
connection: network_cli
tasks:
- block:
- name: show keypair
nxos_command:
commands: "show username someuser keypair"
ignore_unreachable: true
register: print_output
failed_when: ("could not retrieve rsa key information" in print_output.stdout)
- debug: var=print_output
Here's what the debug output looks like. I want to match on the 3rd line of the stdout_lines.
ok: [switchB] => {
"print_output": {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"failed": false,
"failed_when_result": false,
"stdout": [
"**************************************\n\ncould not retrieve rsa key information\n**************************************\n\ncould not retrieve dsa key information\n**************************************\n\ncould not retrieve ecdsa key information\n**************************************"
],
"stdout_lines": [
[
"**************************************",
"",
"could not retrieve rsa key information",
"**************************************",
"",
"could not retrieve dsa key information",
"**************************************",
"",
"could not retrieve ecdsa key information",
"**************************************"
]
]
}
}