We earn commission when you buy through affiliate links.
This does not influence our reviews or recommendations.Learn more.
I will show you several operations which an administrator can perform on a remote windows system using ansible-playbook.
Ansibleis one of the most used DevOps tools in the market today.
It provides a bunch of windows modules that are used to configure and manage the Windows server.
I assume you already haveAnsible installed on Windowsfrom where you want to manage the Windows servers.
The following are some of the commonly used tasks performed by Windows administrators on a daily basis.
You will be amazed to see how easy it is administered Windows using Ansible.
My Ansible Windows controller machines IP address is 192.168.0.106, and my remote Windows systems IP address is 192.168.0.102.
My connection to a remote host is successful.
I will use this module to copy a single PDF.
Use the below YAML code, give the source and destination paths.
trigger the ansible-playbook for win_copy.
The file has been copied successfully at the destination location on a remote windows system.
Here, I am installing Apache.
YAML code to be used:
initiate the ansible-playbook to install using MSI.
Now, go to the windows system and look to see if the apache system got installed successfully.
you’ve got the option to also install applications using MSI with arguments.
To uninstall an app using the MSI file, it’s crucial that you use thewin_packagemodule.
The state absent means the software will be uninstalled using the MSI file.
Here, I am uninstalling Apache.
trigger the ansible-playbook to uninstall using MSI.
initiate the ansible-playbook to uninstall 7-Zip.
Stop/Start/Restart Windows Services
win_serviceansible module is used to start, stop, or restart a service.
Here, I will show you how to stop the tomcat service.
you oughta mention the service name in the YAML file and set the state to stop.
fire off the ansible-playbook to stop the tomcat service.
If you check the tomcat service on the windows system, it is now in stopped status.
execute the ansible-playbook to get the disk information.
fire off the ansible-playbook to get remote system information.
Running Commands
Whatever commands you run on a window, they can be run through the ansiblewin_commandmodule.
You just need to specify the command in your YAML file.
Here, I am just creating a directory.
launch the ansible-playbook to perform win_command operation.
Environment Variables
A windows system has multiple environment variables, for example, JAVA_HOME.
Using thewin_environmentansible module, you might add or modify environment variables on a windows system.
In this example, I am adding a new variable to the windows environment variables list.
trigger the ansible-playbook to add the environment variable on a remote windows machine.
Go to the environment variables window; you will see the new variable you just added is present here.
Add/Edit Registry
win_regeditansible module is used to add or edit registry details on a remote windows machine.
you gotta give the path of the registry and content to be added/updated.
execute the ansible-playbook to add the registry.
Go to Windows Powershell, and list the EventLogs present on the remote windows machine.
Now, I will show how to remove logs from all sources for Internet Explorer.
launch the ansible-playbook to remove the Internet Explorer form the remote windows machine.
Now, if you list the EventLogs again, you will see Internet Explorer logs have been removed.
So, that was all about Ansible playbooks, which can be used for remote windows administration.
Go ahead and try out these playbooks.
it’s possible for you to also try otherAnsible Windows modulesavailable.