Hello, I currently have a playbook that retrieves information from a Cisco machine in a text file. Then I run a scipt bash run by ansible to check the patch version.
The problem is that this way of doing things does not respect idempotence.
Do you know a module to check that a line exists within the file or even a variable and which returns an “OK” if the line exists ?
What is in reply? Instead of putting in a file and then running your script against that, you might be able to directly get the value from the registered variable. Put a debug module after ios_command and print out result.
Yes, I can actually do as you say and not go through a text file. The purpose of this playbook is to do nothing if the right version is installed and otherwise install the right one.
Something like.
If {{ result }} != “Version 5”
then
install Version 5
fi
But I don’t know how to isolate and test the string “Version: x” directly in Ansible
Right. Which is why I suggested printing it out with a debug statement. You should then be able to determine the best way to split/join to isolate your output and then use a subsequent when statement to decide if to proceed with the desired update. Make sense?