Version of package installed with apt?

11 views
Skip to first unread message

René Pijlman

unread,
Mar 29, 2016, 10:10:10 AM3/29/16
to Ansible Project
Is there an elegant way to find out what the version of an installed package (say with the apt module) is?

I now have this code to get PostgreSQL's configdir on Debian:

- name: required packages for PostgreSQL
  apt: name={{ item }} state=present
  with_items:
  - postgresql
  - postgresql-client

- name: version of installed PostgeSQL server package
  shell:  dpkg-query -W --showformat='${Version}' postgresql | cut --delimiter=+ --fields=1
  register: pv
  changed_when: False

- name: postgresql version
  set_fact:
    postgresql_version: "{{ pv.stdout }}"

- name: postgresql configdir
  set_fact:
    postgresql_configdir: "/etc/postgresql/{{ postgresql_version }}/main"

But I find the dpkg-query|cut a bit ugly. Is there a better way?
Reply all
Reply to author
Forward
0 new messages