This blog post will show you how to restart a service on Ubuntu Linux using Ansible built-in module for service management.
By default, any Ansible installation comes with the service module, and it is also part of the Ansible-base set of modules. Using the service module, we can manage and control the following service states:
We can also configure the service to auto-start or be in a stop state when the server comes up using the enable key.
In the following configuration, restart the Nginx service on Ubuntu Server 20.04 and set the service to auto-start.
--- - hosts: servers tasks: - name: restart nginx service: name: nginx state: restarted enabled: yes