Last active
July 16, 2019 14:43
-
-
Save jadia/4a86d6c45fd5e7da3acb6cfb5f9fa54d to your computer and use it in GitHub Desktop.
Ansible: Check if a process is already running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if process is already running if not then set the false flag | |
- name: Check if authCheck process is running | |
shell: | | |
bash -c "if lsof /usr/local/sshAuthKeyNotify.sh ; then | |
echo 'Process ALREADY running' | |
true | |
else | |
echo 'PROCESS NOT RUNNING' | |
false | |
fi" | |
register: processPresent | |
ignore_errors: yes | |
tags: this | |
# Run the below task only when processPresent is false | |
- name: Run the file once in background | |
shell: "nohup /bin/bash /usr/local/sshAuthKeyNotify.sh >/dev/null 2>&1 &" | |
when: processPresent is failed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment