On 27.08.2019 21:10, JP-OKC wrote: > 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. > > Here's what the playbook looks like: > > --- > - 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": [
As you can see here the [ indicate a list so first element is 0. The nxos_command takes several commands, the first command is in list element 0, the second one is list element 1 and so on.... so you need to use element 0 like this failed_when: ("could not retrieve rsa key information" in print_output.stdout.0) -- Kai Stian Olstad -- 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-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2192b02c-03f3-92ee-9f18-8ac65f342adf%40olstad.com.