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.

Services

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

tasks:

– name: start service

win_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

tasks:

– name: start service

win_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.

Processing…
Success! You're on the list.

Leave a Reply

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