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

后端 未结 7 1275
执念已碎
执念已碎 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 01:58

    I find using shell or command module is not "ansiblic".

    I prefer to use yum module and json_query filter to check if a package is already installed. E.g. httpd package :

        - yum:
            list: httpd
          register: apache_service
    
        - assert:
            that:
              - "'installed' in apache_service|json_query('results[*].yumstate')"
          msg: 'httpd is not installed'
    

提交回复
热议问题