Eric Marquez
unread,Nov 23, 2016, 10:25:21 AM11/23/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible-project (ansible-project@googlegroups.com)
I'm working with some Dell OS 9 switches. I'm attempting to remove a command from the configuration. That part works. The part I'm having problems with is validating it was indeed removed from the configuration.
How do I do a validation check to ensure and command does not exist or is not contained in a result.
For example, I am removing the line from the configuration: "neighbor MUX_IPV4Clst[1-20] distribute-list external-prefix out", but there are multiple group names that will match and all are being removed.
- name: show running bgp
dellos9_command:
provider: "{{ cli }}"
commands:
- "do show run bgp | grep MUX_IPV4Clst3 | grep distribute"
# wait_for:
# - result.stdout ne 'distribute-list'
register: output
- name: debug
debug: var=output
- name: check bgp
shell: "echo {{ output.stdout_lines[0] }}"
# when:
# - output != "distribute-list"
when: output.stdout.find('distribute-list') != -1
TASK [removeprefix : show running bgp] *****************************************
task path: /mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/dell/force10/roles/removeprefix/tasks/main.yml:27
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/network/dellos9/dellos9_command.py
<10.10.234.98> ESTABLISH LOCAL CONNECTION FOR USER: emarq
<10.10.234.98> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1479914628.77-259380380959531 `" && echo ansible-tmp-1479914628.77-259380380959531="` echo $HOME/.ansible/tmp/ansible-tmp-1479914628.77-259380380959531 `" ) && sleep 0'
<10.10.234.98> PUT /tmp/tmpgRL22M TO /home/emarq/.ansible/tmp/ansible-tmp-1479914628.77-259380380959531/dellos9_command.py
<10.10.234.98> EXEC /bin/sh -c 'chmod u+x /home/emarq/.ansible/tmp/ansible-tmp-1479914628.77-259380380959531/ /home/emarq/.ansible/tmp/ansible-tmp-1479914628.77-259380380959531/dellos9_command.py && sleep 0'
<10.10.234.98> EXEC /bin/sh -c '/usr/bin/python /home/emarq/.ansible/tmp/ansible-tmp-1479914628.77-259380380959531/dellos9_command.py; rm -rf "/home/emarq/.ansible/tmp/ansible-tmp-1479914628.77-259380380959531/" > /dev/null 2>&1 && sleep 0'
ok: [rr1-n22-r13-4048hl-5-1b] => {
"changed": false,
"invocation": {
"module_args": {
"auth_pass": null,
"authorize": false,
"commands": [
"do show run bgp | grep MUX_IPV4Clst3 | grep distribute"
],
"host": "10.10.234.98",
"interval": 1,
"password": null,
"port": null,
"provider": {
"host": "10.10.234.98",
"ssh_keyfile": "/srv/tftpboot/masd-rsa.pub",
"transport": "cli",
"username": "admin"
},
"retries": 10,
"ssh_keyfile": "/srv/tftpboot/masd-rsa.pub",
"timeout": 10,
"transport": "cli",
"username": "admin",
"wait_for": null
},
"module_name": "dellos9_command"
},
"stdout": [
"do show run bgp | grep MUX_IPV4Clst3 | grep distribu\u001b[52D \u001b[55D$run bgp | grep MUX_IPV4Clst3 | grep distribute\n neighbor MUX_IPV4Clst3 distribute-list external-prefix out"
],
"stdout_lines": [
[
"do show run bgp | grep MUX_IPV4Clst3 | grep distribu\u001b[52D \u001b[55D$run bgp | grep MUX_IPV4Clst3 | grep distribute",
" neighbor MUX_IPV4Clst3 distribute-list external-prefix out"
]
],
"warnings": []
}
TASK [removeprefix : debug] ****************************************************
task path: /mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/dell/force10/roles/removeprefix/tasks/main.yml:36
ok: [rr1-n22-r13-4048hl-5-1b] => {
"output": {
"changed": false,
"stdout": [
"do show run bgp | grep MUX_IPV4Clst3 | grep distribu\u001b[52D \u001b[55D$run bgp | grep MUX_IPV4Clst3 | grep distribute\n neighbor MUX_IPV4Clst3 distribute-list external-prefix out"
],
"stdout_lines": [
[
"do show run bgp | grep MUX_IPV4Clst3 | grep distribu\u001b[52D \u001b[55D$run bgp | grep MUX_IPV4Clst3 | grep distribute",
" neighbor MUX_IPV4Clst3 distribute-list external-prefix out"
]
],
"warnings": []
}
}
TASK [removeprefix : check bgp] ************************************************
task path: /mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/dell/force10/roles/removeprefix/tasks/main.yml:39
fatal: [rr1-n22-r13-4048hl-5-1b]: FAILED! => {
"failed": true,
"msg": "The conditional check 'output.stdout.find('distribute-list') != -1' failed. The error was: error while evaluating conditional (output.stdout.find('distribute-list') != -1): 'list object' has no attribute 'find'\n\nThe error appears to have been in '/mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/dell/force10/roles/removeprefix/tasks/main.yml': line 39, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: check bgp\n ^ here\n"
}
to retry, use: --limit @/mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/dell/force10/removetorprefix.retry
PLAY RECAP *********************************************************************
rr1-n22-r13-4048hl-5-1b : ok=9 changed=5 unreachable=0 failed=1