• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Start and Stop Services in Windows by Using Ansible Playbook on Oracle Linux 8.5

  • 00:36 cat /etc/os-release
  • 00:54 yum list ansible
  • 01:10 yum list python3
  • 01:30 pip3 list | grep pywinrm
  • 01:45 vim /etc/ansible/hosts
  • 02:34 vim start.yml
  • 04:09 ansible-playbook start.yml --syntax-check
  • 04:28 ansible-playbook start.yml
  • 05:08 vim stop.yml
  • 06:30 ansible-playbook stop.yml --syntax-check
  • 06:48 ansible-playbook stop.yml
{{postValue.id}}

To Start and Stop Services in windows by using Ansible Playbook on Oracle Linux 8.5

Introduction:

Windows Services is a core feature of the Microsoft Windows operating system that enables the creation and management of long-running processes Using the win_service ansible module, you can start, stop, and restart services

Procedure:

Master Server Requirements: ansible python3-pip pywinrm (python package)

Windows Requirements: powershell 3+ Dot net 4

Installation Procedure:

Step 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="8.5"
ID="ol"
ID_LIKE="fedora"

Step 2: Check the availability of Ansible package, python3-pip package, by using the below command

[root@linuxhelp ~]# yum list ansible
ansible.noarch                        2.9.27-1.el8                         @ol8_developer_EPEL
Available Packages
ansible.src                           2.9.27-1.el8                         ol8_developer_EPEL 

[root@linuxhelp ~]# yum list python3
Last metadata expiration check: 1:28:13 ago on Sun 11 Sep 2022 03:22:41 PM IST.
Available Packages
python3.src                         3.6.8-45.0.1.el8                         ol8_baseos_latest
python3.src                         3.6.8-45.0.1.el8                         ol8_appstream    

[root@linuxhelp ~]# pip3 list | grep pywinrm
pywinrm (0.4.3)

Step 3: Create inventory for Windows node system by using the below command

[root@linuxhelp ~]# vim /etc/ansible/hosts
[windows]
192.168.6.51

[windows:vars]
ansible_user=Admin
ansible_password=Linuxc#4
ansible_port=5986
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

Step 4: Create a playbook to Start the Service in windows by using the below command

root@linuxhelp:~# vim start.yml
---
- hosts: windows

  tasks:

   - name: start service windows update

     win_service:

       name: wuauserv

       state: started

Step 5: Check the syntax of the start.yml ansible playbook by using the below command

root@linuxhelp:~# ansible-playbook start.yml --syntax-check

playbook: start.yml

Step6: Run the start.yml playbook by using the below command

[root@linuxhelp ~]# ansible-playbook start.yml

PLAY [windows] *****************************************************************************

TASK [Gathering Facts] *********************************************************************
ok: [192.168.6.51]

TASK [start service windows update] ********************************************************
changed: [192.168.6.51]

PLAY RECAP *********************************************************************************
192.168.6.51               : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Step 7: Create a playbook to Stop the Service in windows by using the below command

root@linuxhelp:~# vim stop.yml
---
- hosts: windows

  tasks:

   - name: stop service windows update

     win_service:

       name: wuauserv

       state: stopped

Step 8: Check the syntax of the stop.yml ansible playbook by using the below command

root@linuxhelp:~# ansible-playbook stop.yml --syntax-check
playbook: stop.yml

Step 9: Run the stop.yml playbook by using the below command

[root@linuxhelp ~]# ansible-playbook stop.yml
PLAY [windows] *****************************************************************************

TASK [Gathering Facts] *********************************************************************
ok: [192.168.6.51]

TASK [Stop service windows update] *********************************************************
changed: [192.168.6.51]

PLAY RECAP *********************************************************************************
192.168.6.51               : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Conclusion

We have reached the end of this article. In this guide, we have walked you through the steps required to Start and Stop services in windows by using Ansible Playbook on Oracle Linux 8.5. Your feedback is much welcome.

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

How do Windows services work?

A

Microsoft Windows services, formerly known as NT services, enable you to create long-running executable applications that run in their own Windows sessions.

Q

When should you use Windows services?

A

You should create a Windows Service to run code in the background, without user interaction

Q

Where are Windows services located?

A

The Services file is typically located in %windir%\System32\drivers\etc\services.

Q

Can a Windows service launch an application?

A

Windows Services cannot start additional applications because they are not running in the context of any particular user

Q

How do I check services?

A

Press the Win + R keys on your keyboard, to open the Run window. Then, type "services. msc" and hit Enter or press OK.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ryan ?
how to use visual traceroute tool

Am using traceroute command to check for the route. i got this tool while surfing. So pls help me out installation and usage of Visual traceroute tool.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.