How to install an application on Windows by using Ansible playbook
- 01:20 Set-ExecutionPolicy Bypass -Scope Process -Force;
- 02:03 apt list -a ansible
- 02:18 apt list -a python3-pip
- 02:55 ansible-galaxy collection install chocolatey.chocolatey
- 03:42 vi /etc/ansible/hosts
- 06:10 ansible-playbook install.yml --syntax-check
- 06:31 ansible-playbook install.yml
- 07:28 vi uninstall.yml
- 09:08 ansible-playbook uninstall.yml --syntax-check
- 09:28 ansible-playbook uninstall.yml
To Install an Application on Windows by using Ansible playbook
Introduction:
Ansible is an open-source tool for managing software configurations and deploying applications. Chocolately is a management tool for Windows software.
Master Server Requirements:
ansible
python3-pip
pywinrm (python package
Windows Requirements:
powershell 3+
Dot net 4
Installation Procedure:
Step 1: Search for chocolatey in browser
Step 2: Copy the installation command in chocolatey install page
Step 3: Run Powershell ISE as an administrator
Step 4: Install chocolatey by using the following command
PS C:\WINDOWS\system32> Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/0.11.3.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/0.11.3 to C:\Users\Admin\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\Admin\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\Admin\AppData\Local\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
(i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.
Step 5: Check the OS version by using the following command
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute
Step 6: Check the availability of Ansible package
root@linuxhelp:~# apt list -a ansible
Listing... Done
ansible/hirsute,hirsute,now 4.8.0-1ppa~hirsute all [installed]
ansible/hirsute,hirsute 2.10.7-1 all
Step 7: Check the availability of python3-pip package
root@linuxhelp:~# apt list -a python3
Listing... Done
python3/hirsute,now 3.9.4-1 amd64 [installed,automatic]
python3/hirsute 3.9.4-1 i386
Step 8: Check the availability of python package pywinrm
root@linuxhelp:~# pip list | grep pywinrm
pywinrm 0.4.2
ansible_winrm_server_cert_validation=ignore
Step 9: Install the plugins of chocolatey for ansible
root@linuxhelp:~# ansible-galaxy collection install chocolatey.chocolatey
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.
Step 10:Create inventory for Windows node system
root@linuxhelp:~# vi /etc/ansible/hosts
[windows]
192.168.2.134
[windows:vars]
ansible_user=Admin
ansible_password=Admin@123
ansible_port=5986
ansible_connection=winrm
Step 11:Create playbook for installing namecoin application
root@linuxhelp:~# vi install.yml
hosts: windows
gather_facts: true
tasks:
- name: install namecoin
win_chocolatey:
name: namecoin
state: present
Step 12: Check the syntax of the install.yml ansible playbook by using the following command
root@linuxhelp:~# ansible-playbook install.yml --syntax-check
playbook: proxyset.yml
Step 13: Run the install.yml playbook by using the following command
root@linuxhelp:~# ansible-playbook install.yml
PLAY [windows] **************************************************************************************
TASK [Gathering Facts] ******************************************************************************
ok: [192.168.2.134]
TASK [install namecoin] *****************************************************************************
changed: [192.168.2.134]
PLAY RECAP ******************************************************************************************
192.168.2.134 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Step 14 : Namecoin application installed on Windows Client system
Step 15: Create playbook for uninstall namecoin application
root@linuxhelp:~# vi uninstall.yml
- hosts: windows
gather_facts: true
tasks:
- name: Uninstall namecoin
win_chocolatey:
name: namecoin
state: absent
~
Step 16: Check the syntax of the uninstall.yml ansible playbook by using the following command
root@linuxhelp:~# ansible-playbook uninstall.yml --syntax-check
playbook: removeproxy.yml
Step 17: Run the uninstall.yml playbook by using the following command
root@linuxhelp:~# ansible-playbook uninstall.yml
PLAY [windows] **************************************************************************************
TASK [Gathering Facts] ******************************************************************************
ok: [192.168.2.134]
TASK [Uninstall namecoin] ***************************************************************************
changed: [192.168.2.134]
PLAY RECAP ******************************************************************************************
192.168.2.134 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Step 18: Namecoin application Uninstalled on Windows Client system
With this installation of an application on Windows by using Ansible comes to an end
Comments ( 0 )
No comments available