Howto remove one apt package if the version differ

20 views
Skip to first unread message

J M

unread,
Sep 21, 2023, 2:31:12 PM9/21/23
to Ansible Project
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




Brian Coca

unread,
Sep 21, 2023, 2:39:31 PM9/21/23
to ansible...@googlegroups.com
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

--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages