Reputation: 31
Ansible is skipping the execution of a task even when my conditional string is meeting the requirement and I can see this string in the stdout.
I tried playing around with the content option in copy module where I replaced {{inventory_hostname}} with {{ansible_host}}
I tried replacing result.stdout_lines with result.stdout as the stdout output is a dictionary.
---
- name: Detecting NXOS 5K devices which fail the 'copy run start' from device inventory
hosts: nxos-5k
gather_facts: false
connection: local
tasks:
- name: Gather device specific facts
nxos_facts:
gather_subset: config
register: net_facts
- name: Executing 'copy run start' on NXOS 5K chassis
nxos_command:
commands:
- 'copy run start'
register: result
ignore_errors: True
- debug: var=result.stdout_lines
- name: Copy the device name to failed device list
copy:
content: "{{inventory_hostname}}"
dest: /home/saurasar/ansibledev/results/failed_nxos_devices.txt
when: "'Configuration update aborted: request was aborted' in result.stdout_lines"
Expected result: String search should be successful as I can see from -vvv that result.stdout contains the string.
"stdout_lines": [[0m
[0;32m [[0m
[0;32m "[# ] 1%", [0m
[0;32m "[# ] 2%", [0m
[0;32m "[## ] 3%", [0m
[0;32m "[## ] 4%", [0m
[0;32m "[### ] 5%", [0m
[0;32m "[### ] 6%", [0m
[0;32m "[### ] 7%", [0m
[0;32m "[#### ] 8%", [0m
[0;32m "[##### ] 10%", [0m
[0;32m "[##### ] 11%", [0m
[0;32m "[##### ] 12%", [0m
[0;32m "[###### ] 13%", [0m
[0;32m "[###### ] 14%", [0m
[0;32m "[####### ] 15%", [0m
[0;32m "[####### ] 16%", [0m
[0;32m "[####### ] 17%", [0m
[0;32m "[######## ] 19%", [0m
[0;32m "[######### ] 20%", [0m
[0;32m "[######### ] 21%", [0m
[0;32m "[######### ] 22%", [0m
[0;32m "[########## ] 23%", [0m
[0;32m "[########## ] 24%", [0m
[0;32m "[########### ] 25%", [0m
[0;32m "[########### ] 26%", [0m
[0;32m "[############ ] 28%", [0m
[0;32m "[############ ] 29%", [0m
[0;32m "[############# ] 30%", [0m
[0;32m "[############# ] 31%", [0m
[0;32m "[############# ] 32%", [0m
[0;32m "[############## ] 33%", [0m
[0;32m "[############## ] 34%", [0m
[0;32m "[############### ] 35%", [0m
[0;32m "[############### ] 37%", [0m
[0;32m "[################ ] 38%", [0m
[0;32m "[################ ] 39%", [0m
[0;32m "[################# ] 40%", [0m
[0;32m "[################# ] 41%", [0m
[0;32m "[################# ] 42%", [0m
[0;32m "[################## ] 43%", [0m
[0;32m "[################## ] 44%", [0m
[0;32m "[################### ] 46%", [0m
[0;32m "[################### ] 47%", [0m
[0;32m "[#################### ] 48%", [0m
[0;32m "[#################### ] 49%", [0m
[0;32m "[##################### ] 50%", [0m
[0;32m "[##################### ] 51%", [0m
[0;32m "[##################### ] 52%", [0m
[0;32m "[###################### ] 53%", [0m
[0;32m "[####################### ] 55%", [0m
[0;32m "[####################### ] 56%", [0m
[0;32m "[####################### ] 57%", [0m
[0;32m "[######################## ] 58%", [0m
[0;32m "[######################## ] 59%", [0m
[0;32m "[######################### ] 60%", [0m
[0;32m "[######################### ] 61%", [0m
[0;32m "[######################### ] 62%", [0m
[0;32m "[########################## ] 64%", [0m
[0;32m "[########################### ] 65%", [0m
[0;32m "[########################### ] 66%", [0m
[0;32m "[########################### ] 67%", [0m
[0;32m "[############################ ] 68%", [0m
[0;32m "[############################ ] 69%", [0m
[0;32m "[############################# ] 70%", [0m
[0;32m "[############################# ] 71%", [0m
[0;32m "[############################## ] 73%", [0m
[0;32m "[############################## ] 74%", [0m
[0;32m "[############################### ] 75%", [0m
[0;32m "[############################### ] 76%", [0m
[0;32m "[############################### ] 77%", [0m
[0;32m "[################################ ] 78%", [0m
[0;32m "[################################ ] 79%", [0m
[0;32m "[################################# ] 80%", [0m
[0;32m "[################################# ] 82%", [0m
[0;32m "[################################## ] 83%", [0m
[0;32m "[################################## ] 84%", [0m
[0;32m "[################################### ] 85%", [0m
[0;32m "[################################### ] 86%", [0m
[0;32m "[################################### ] 87%", [0m
[0;32m "[#################################### ] 88%", [0m
[0;32m "[#################################### ] 89%", [0m
[0;32m "[##################################### ] 91%", [0m
[0;32m "[##################################### ] 92%", [0m
[0;32m "[###################################### ] 93%", [0m
[0;32m "[###################################### ] 94%", [0m
[0;32m "[####################################### ] 95%", [0m
[0;32m "[####################################### ] 96%", [0m
[0;32m "[####################################### ] 97%", [0m
[0;32m "[########################################] 98%", [0m
[0;32m "[########################################] 100%", [0m
[0;32m "Copy complete, now saving to disk (please wait)..."[0m
Actual result:
TASK [Copy the device name to failed device list] ***********************************************************************************************************************************************************************
task path: /home/saurasar/ansibledev/failure.detection.2.yml:22
skipping: [Device hostname] => {
"changed": false,
"skip_reason": "Conditional result was False"
}
META: ran handlers
META: ran handlers
Upvotes: 1
Views: 6128
Reputation: 31
After some more trying, I found another way and looks like that fixed the problem! I just added [0] at the end of stdout and it did the trick. when: "'Configuration update aborted: request was aborted' in result.stdout_lines[0]"
Upvotes: 1