Skip to content

Instantly share code, notes, and snippets.

@jadia
Last active July 16, 2019 14:43
Show Gist options
  • Save jadia/4a86d6c45fd5e7da3acb6cfb5f9fa54d to your computer and use it in GitHub Desktop.
Save jadia/4a86d6c45fd5e7da3acb6cfb5f9fa54d to your computer and use it in GitHub Desktop.
Ansible: Check if a process is already running
# 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