How to make Ansible execute a shell script if a pa

2019-03-08 01:38发布

How can I make Ansible execute a shell script if a (rpm) package is not installed? Is it somehow possible to leverage the yum module?

标签: ansible
7条回答
戒情不戒烟
2楼-- · 2019-03-08 02:25

You shouldn't be using dpkg -l package because it has no idea if your package has been removed or is still installed.
Instead it's probably better to use dpkg -s package.

To check if the package is installed :
- shell: dpkg -s package | grep 'install ok installed'
or if you don't mind the package on hold or other states :
- shell: dpkg -s package | grep 'installed'
This return 0 when installed and 1 if not.

(It's important to use the shell as we are using a pipe |)

查看更多
登录 后发表回答