check the patch version

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 ?

Thank you in advance

Could you give some more details and possibly your ansible code and output? What type of Cisco device? Switch, firewall, etc?

[Playbook]

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?

Yeah, I see. I didn’t think of that. I’ll try tomorrow. I’ll keep you informed. Thank you very much for your time.

“Qui facit per alium facit per se.”

Ok I got it but do you know how to do the reverse for wrong version ? I’ve to remplace “in” by somothing like “is not” or something like that.

debug:
msg=“OK”
when: “‘Version : 7’ in output.stdout_lines[0] | join(‘\n’)”

not in

Okay, I feel stupid. Thx all of you.

Is it working then?

Yes, it works. I think I can optimize it, especially in terms of testing. But he does what I want. Thank you very much.