# check the patch version

**URL:** <https://forum.ansible.com/t/check-the-patch-version/28774>\
**Category:** Ansible Project\
**Created:** [October 12, 2018, 1:12pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774 "2018-10-12T13:12:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexis\_calvayrac](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@alexis\_calvayrac](https://forum.ansible.com/u/alexis_calvayrac)\
**Post date:** [October 12, 2018, 1:12pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774/1 "2018-10-12T13:12:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brad2](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Brad2](https://forum.ansible.com/u/Brad2)\
**Post date:** [October 12, 2018, 1:45pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774/2 "2018-10-12T13:45:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexis\_calvayrac](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@alexis\_calvayrac](https://forum.ansible.com/u/alexis_calvayrac)\
**Post date:** [October 12, 2018, 1:58pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774/3 "2018-10-12T13:58:14Z")

</div>

[Playbook]

---

<div class="post-metadata">

**Author:** ![Brad2](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Brad2](https://forum.ansible.com/u/Brad2)\
**Post date:** [October 12, 2018, 3:02pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774/4 "2018-10-12T15:02:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alexis\_calvayrac](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@alexis\_calvayrac](https://forum.ansible.com/u/alexis_calvayrac)\
**Post date:** [October 12, 2018, 3:22pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774/5 "2018-10-12T15:22:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brad2](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Brad2](https://forum.ansible.com/u/Brad2)\
**Post date:** [October 12, 2018, 3:30pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774/6 "2018-10-12T15:30:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alexis\_calvayrac](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@alexis\_calvayrac](https://forum.ansible.com/u/alexis_calvayrac)\
**Post date:** [October 12, 2018, 3:59pm UTC](https://forum.ansible.com/t/check-the-patch-version/28774/7 "2018-10-12T15:59:01Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![alexis\_calvayrac](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@alexis\_calvayrac](https://forum.ansible.com/u/alexis_calvayrac)\
**Post date:** [October 17, 2018, 8:07am UTC](https://forum.ansible.com/t/check-the-patch-version/28774/8 "2018-10-17T08:07:43Z")

</div>

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’)”

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 17, 2018, 8:32am UTC](https://forum.ansible.com/t/check-the-patch-version/28774/9 "2018-10-17T08:32:07Z")

</div>

not in

---

<div class="post-metadata">

**Author:** ![alexis\_calvayrac](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@alexis\_calvayrac](https://forum.ansible.com/u/alexis_calvayrac)\
**Post date:** [October 17, 2018, 8:42am UTC](https://forum.ansible.com/t/check-the-patch-version/28774/10 "2018-10-17T08:42:54Z")

</div>

Okay, I feel stupid. Thx all of you.

---

<div class="post-metadata">

**Author:** ![Brad2](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Brad2](https://forum.ansible.com/u/Brad2)\
**Post date:** [October 17, 2018, 10:12am UTC](https://forum.ansible.com/t/check-the-patch-version/28774/11 "2018-10-17T10:12:34Z")

</div>

Is it working then?

---

<div class="post-metadata">

**Author:** ![alexis\_calvayrac](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@alexis\_calvayrac](https://forum.ansible.com/u/alexis_calvayrac)\
**Post date:** [October 17, 2018, 11:29am UTC](https://forum.ansible.com/t/check-the-patch-version/28774/12 "2018-10-17T11:29:00Z")

</div>

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