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
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.
Comments ( 0 )
No comments available