# Version of package installed with apt?

**URL:** <https://forum.ansible.com/t/version-of-package-installed-with-apt/21006>\
**Category:** Ansible Project\
**Created:** [March 29, 2016, 11:16am UTC](https://forum.ansible.com/t/version-of-package-installed-with-apt/21006 "2016-03-29T11:16:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rene\_Pijlman](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@Rene\_Pijlman](https://forum.ansible.com/u/Rene_Pijlman)\
**Post date:** [March 29, 2016, 11:16am UTC](https://forum.ansible.com/t/version-of-package-installed-with-apt/21006/1 "2016-03-29T11:16:26Z")

</div>

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?
