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

后端 未结 7 1057
执念已碎
执念已碎 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:09

    Based on the Bruce P answer above, a similar approach for apt/deb files is

    - name: Check if foo is installed
      command: dpkg-query -l foo
      register: deb_check
    
    - name: Execute script if foo is not installed
      command: somescript
      when: deb_check.stdout.find('no packages found') != -1
    

提交回复
热议问题