# Howto remove one apt package if the version differ

**URL:** <https://forum.ansible.com/t/howto-remove-one-apt-package-if-the-version-differ/38459>\
**Category:** Ansible Project\
**Created:** [September 21, 2023, 6:31pm UTC](https://forum.ansible.com/t/howto-remove-one-apt-package-if-the-version-differ/38459 "2023-09-21T18:31:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesarjorgemartinez](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cesarjorgemartinez/32/163_2.png) [@cesarjorgemartinez](https://forum.ansible.com/u/cesarjorgemartinez)\
**Post date:** [September 21, 2023, 6:31pm UTC](https://forum.ansible.com/t/howto-remove-one-apt-package-if-the-version-differ/38459/1 "2023-09-21T18:31:12Z")

</div>

Hi,

I need to remove one apt package but only if differ the version, example should be:

- name: remove package  
apt:  
name:
- “htop!=2.2.0-2build1”  
status: absent

Or something as:

- name: remove package  
apt:  
name:
- htop  
status: absent  
when: htop version != ‘2.2.0-2build1’

Howto write this task?

Regards

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 21, 2023, 6:39pm UTC](https://forum.ansible.com/t/howto-remove-one-apt-package-if-the-version-differ/38459/2 "2023-09-21T18:39:05Z")

</div>

2 ways I can think of, first is use 'package\_facts' to get the info  
for version, the other is a shell task with something like `apt show  
htop\>grep Version|cut -f 2 -d':'`

Then you write the apt task using version test.  
[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/version\_test.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/version_test.html)
