This blog post will show you how to restart a service on Ubuntu Linux using Ansible built-in module for service management.
Service
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:
- reloaded
- restarted
- started
- stopped
We can also configure the service to auto-start or be in a stop state when the server comes up using the enable key.
Configuration
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
Processing…
Success! You're on the list.
Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.