How to make Ansible execute a shell script if a package is not installed

后端 未结 7 1075
执念已碎
执念已碎 2021-01-30 01:48

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?

7条回答
  •  滥情空心
    2021-01-30 02:14

    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 |)

提交回复
热议问题