简体   繁体   中英

Getting the version number of a package in ubuntu for use in Ansible

I need to write a command that returns only a version number of a package, something like:

docker --version Docker version 1.10.3, build 20f81dd

But that returns only the 1.10.3 part.

I need this for an Ansible playbook. Trying to parse the --version works only if the package is installed, but when it isn't it throws errors. I'm hesitant to interprete the error as an absence of the package, an can't find anything that suits my needs.

I've tried several commands:

dpkg -l 'docker' | grep 'Version' apt-cache policy docker | grep Installed

Both do their work, but Ansible gets huge amounts of excess data (as in every package file and their info, and that's no good if there are a lot of machines sending all that data around)

Is this even possible? Or should I look for a work-around?

Many thanks!

This works for me :

➜  ~ dpkg -l |grep docker | awk 'NR==1{ print $3 }'| tr "~" "\n" | grep -v trusty
1.9.1-0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM