Search code examples
ansibleansible-inventory

Ansible playbook check if service is up if not - install something


i need to install Symantec endpoint security on my linux system and im trying to write a playbook to do so

when i want to install the program i use ./install.sh -i but after the installation when i run the installation again i get this msg:

root@TestKubuntu:/usr/SEP# ./install.sh -i
Starting to install Symantec Endpoint Protection for Linux
Downgrade is not supported. Please make sure the target version is newer than the original one.

this is how i install it in the playbook

 - name: Install_SEP
     command: bash /usr/SEP/install.sh -i

I would like if it's possible to maybe check if the service is up and if there is no service then install it or maybe there is a better way doing this.

Thank you very much for your time


Solution

  • Please try something like below.

    - name: Check if service is up
      command: <command to check if service is up>
      register: output
    
    - name: Install_SEP
      command: bash /usr/SEP/install.sh -i  
      when: "'running' not in output.stdout"
    

    Note: I have used running in when condition : If the service command returns something specific, include that instead of running.