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

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

    If the package is installable through the system package manager (yum, apt, etc) itself, then you can make use of the check mode flag of ansible to register installation status without actually installing the package.

    - name: check if package is installed
      package:
        name: mypackage
        state: present
      check_mode: true
      register: mypackage_check
    
    - name: run script if package installed
      shell: myscript.sh
      when: not mypackage_check.changed 
    
    0 讨论(0)
提交回复
热议问题