AMP AMP

How to install and uninstall Software in Windows by using Ansible Playbook on Oracle Linux 8.5

To Install And Uninstall A Software In Windows By Using Ansible On Oracle Linux 8.5

Introduction:

Ansible Playbooks are performed on a set, group, or classification of hosts, which concurrently make up an Ansible inventory.Ansible can be used to handle and execute core functions in Windows environments.Win_package module is used to install or uninstall a package.

Installation 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, 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.104

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

Step 4: You can Install a software with .exe file using the product id of that software. Create a playbook for installing 7-Zip by using the below command

root@linuxhelp:~# vim install.yml
---

- hosts: windows

  tasks:

   - name: Install 7-Zip from the exe

     win_package:

       path: F:\7-Zip.exe

       product_id: 7-Zip

       arguments: /S

       state: present

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

[root@linuxhelp ~]# ansible-playbook install.yml --syntax-check
playbook: install.yml

Step 6: Run the install.yml playbook by using the below command

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

Step 7: Now 7-Zip has been Installed in windows as shown in the below image

Step 8: You can also uninstall software with .exe file using the product id of that software. Create playbook for Uninstalling 7-Zip by using the below command

root@linuxhelp:~# vim  uninstall.yml
---

- hosts: windows

  tasks:

   - name: Uninstall 7-Zip from the exe

     win_package:

       path: C:\Program Files\7-Zip\Uninstall.exe

       product_id: 7-Zip

       arguments: /S

       state: absent

Step 9: Check the syntax of the uninstall.yml ansible playbook by using the below command

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

Step 10: Run the uninstall.yml playbook by using the below command

root@linuxhelp:~# ansible-playbook uninstall.yml

Step 11: Now 7-Zip has been uninstalled in windows 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 Install and Uninstall a Software in Windows by using ansible playbook on Oracle linux 8.5. Your feedback is much welcome.

FAQ
Q
What is Ansible good for?
A
Ansible can be used to provide the underlying infrastructure of your environment, virtualized hosts and hypervisors, network devices, and bare metal servers.
Q
What is a YAML used for?
A
YAML is a data serialization language that is often used for writing configuration files.
Q
What language is Ansible?
A
Ansible is a tool written in Python, and it uses the declarative markup language YAML to describe the desired state of devices and configuration.
Q
Is Ansible still free?
A
Ansible is a free, open-source tool, and it's straightforward to set up and use: Ansible's playbooks don't require any special coding knowledge.
Q
Does Windows need Python to run Ansible?
A
Most of the Ansible modules in Ansible Core are written for a combination of Linux/Unix machines and arbitrary web services. These modules are written in Python and most of them do not work on Windows.