Manage Windows Services With Ansible

In this blog, post, I will show you how to manage Windows server services with Ansible.

In the last few blog post about Ansible, I have shown you the following:

Install Windows Server roles

Manage Windows machine

I recommend you review the above posts.


When it comes to Windows services, we manage them using the win_service module.

The module allows us to do the following:

  • Set the start mode
  • Set the state of the service
  • Control user, path and dependencies

Set Service State

In the below code, I am setting the state of the w32time service to stop from its default start mode (restarted).

– hosts: windows


– name: start service


name: w32time

state: stopped

The options that we have are, Absent, pushed, started, stopped, restarted.

I strongly recommend you do not use absent because it will delete the service from the OS and the only way to get it back it to register a new service.

Set Start mode

To set the start mode, to a manual I will use the following code:

– hosts: windows


– name: start service


name: w32time

start_mode: manual

The options for the start mode are, auto, delayed, disabled a manual.

Once, you save the file, go ahead and run the playbook.

Success! You're on the list.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.