Hello Team,
Hope you all are doing well.
Here is my case:
Tasks > remove.yml
- name: "Check if any job is running"
shell: |
supervisorctl status "{{ job_name }}:*"
register: job_check
- debug:
msg: "{{ job_check.stdout_lines }}"
notify:
- stop job
- remove job
when: RUNNING in job_check.stdout_lines
Output:
TASK [supervisord : Check if any job is running] ****************************************************************************************************
changed: [34.204.229.0] => {
"changed": true,
"cmd": "supervisorctl status \"idle-queue:*\"\n",
"delta": "0:00:00.137281",
"end": "2022-08-12 05:46:48.807981",
"invocation": {
"module_args": {
"_raw_params": "supervisorctl status \"idle-queue:*\"\n",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"rc": 0,
"start": "2022-08-12 05:46:48.670700",
"stderr": "",
"stderr_lines": [],
"stdout": "idle-queue:idle-queue_00 RUNNING pid 32292, uptime 1:21:01\nidle-queue:idle-queue_01 RUNNING pid 32293, uptime 1:21:01\nidle-queue:idle-queue_02 RUNNING pid 32291, uptime 1:21:01",
"stdout_lines": [
"idle-queue:idle-queue_00 RUNNING pid 32292, uptime 1:21:01",
"idle-queue:idle-queue_01 RUNNING pid 32293, uptime 1:21:01",
"idle-queue:idle-queue_02 RUNNING pid 32291, uptime 1:21:01"
]
}
Error:
TASK [supervisord : debug] **************************************************************************************************************************
fatal: [34.204.229.0]: FAILED! => {
"msg": "The conditional check 'RUNNING in job_check.stdout_lines' failed. The error was: error while evaluating conditional (RUNNING in job_check.stdout_lines): 'RUNNING' is undefined\n\nThe error appears to be in '/home/farrukh/Documents/work/devrim/repositories/ansible-playbooks/roles/supervisord/tasks/remove_job.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n ^ here\n"
}
What I’m trying to achieve is that;
1) Check if any job process is running.
2) If the job process found running then; first stop the process and then remove the process.
PS: using handlers.
Handlers > main.yml
---
# handlers file for supervisord
- name: "{{ action }} job"
shell: |
supervisorctl {{ action }}
when: action == "update" or action == "reread"
- name: "{{ action }} job"
shell: |
supervisorctl {{ action }} "{{ job_name }}:*"
when: action != "update" or action != "reread"