Reputation: 225
I have written a small playbook that checks to see if a given process is running on the host machine. I have written this as follows:
- name: checking process running for clients and start process when not
service:
name: marketaccess {{ item.key|lower }} -vi
state: started
register: process
with_dict: "{{ customers }}"
When the dictionary's item.key = BROADWAY and the process I am trying to check is as follows :
But when I run this playbook the error that is reported is:
Could not find the requested service marketacces broadway -vi: host
Please can someone see what I am doing wrong?
Upvotes: 5
Views: 28088
Reputation: 11
There's a new windows module on ansible that can be used for this purpose.
You can find the process name:
Upvotes: 0
Reputation: 1
As per the ansible documentation its better to use the "pid" module to check if there are any processes running. References are below https://docs.ansible.com/ansible/2.9/modules/pids_module.html
Upvotes: 0
Reputation: 3284
I have used pgrep since "ps -ef" output varies between the servers (at least in my case).
- name: "Get process PID"
shell: >
echo -n
$(pgrep {{ item.binary_name }})
args:
executable: "{{ shell_path }}"
register: my_procs
Upvotes: 4
Reputation: 68559
Please can someone see what I am doing wrong?
Service is not the same as process in computing.
There is no module to manage/check processes in Ansible. You can use the command included in the question with shell
module (pay attention to this), register the result and run a task to start the process.
However, it is equally possible that your marketaccess
is in fact a service, or that yet another service creates child processes. There is no way to tell. Refer to the manual of your software.
You can provide arguments to the service
module as arguments
parameter.
Upvotes: 1