How to Update Modified Group Policy in Windows by using Ansible Playbook on Oracle Linux 8.5

How To Update Modified Group Policy On Windows By Using Ansible Playbook

Introduction:

Ansible is an automatic configuration tool that runs on a wide range of windows and UNIX-like systems. The win_shell module is used to run commands on windows systems. The win_unzip module is used to manage achieved files.

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 following 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, pywinrm 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 playbook in the name of policy.yml by using the below command

root@linuxhelp:~# vi policy.yml
- hosts: windows
  gather_facts: true
  tasks:
  - name: Extract the zip file
    win_unzip:
         src: D:\gpt.zip
         dest: C:\Windows\System32\GroupPolicy
  - name: Updating the Group Policy
    win_shell: gpupdate /force

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

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

playbook: policy.yml

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

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

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

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

TASK [Extract the zip file] ****************************************************************
changed: [192.168.6.51]

TASK [Updating the Group Policy] ***********************************************************
changed: [192.168.6.51]

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

Step 7: The Group policy updated in windows client system by Ansible playbook as shown in the below image

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to update modified group policy in windows by using ansible Playbook on Oracle Linux 8.5. Your feedback is much welcome.

FAQ
Q
How do I test the Ansible connection?
A
To test that Ansible is able to connect and run commands and playbooks on your nodes, you can use the following command: ansible all -m ping.
Q
What is an inventory file in Ansible?
A
The Ansible inventory file defines the hosts and groups of hosts upon which commands, modules, and tasks in a playbook operate.
Q
What is Ansible used for in Linux?
A
Ansible is an open-source automation platform that includes configuration management, application deployment, and infrastructure orchestration.
Q
Which port number does Ansible use to control windows?
A
5986 is the port number does Ansible use to control windows.
Q
How does Ansible communicate with Linux?
A
Ansible uses SSH protocol to connect to servers and run tasks.