I tried to use Ansible service module to restart a service but I got an error.
tasks:
- ini_file: dest=/etc/dd-agent/datadog.conf
section=Main
option=use_mount
state=absent
register: ddagent
- service: name='datadog-agent' state=reloaded
when: ddagent.changed
This generated this error: ERROR: change handler (restart datadog) is not defined
I know that an alternative is to execute:
- command: "service datadog-agent restart"
Still, in this case what's the purpose of the service module?
Use systemctl restart ansible-tower to restart services on clustered environments instead. Also you must restart each cluster node for certain changes to persist as opposed to a single node for a localhost install.
Take this code: - hosts: localhost become: yes tasks: - name: Stop and Start ssh service: name: ssh state: stopped and check the status using "service ssh status" .
How to stop a service. Set the name parameter to the service name and the state parameter to stopped to stop a service. If the service is not running, Ansible will do nothing.
If you're checking services, you can do it the Ansible way by running the service_facts module and then checking ansible_local. services["apache2"]. status as well.
You should add the following code:
handlers:
- name: restart datadog
service: name=datadog-agent state=restarted
The problem that you are facing is that you don't have the handler defined. This will do the job
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With