Blog

Ansible Playbook - Automatically Install MSI & EXE Files

11/11/2023 2 min read
Ansible Playbook - Automatically Install MSI & EXE Files

Automate Software Installation on Windows with Ansible

Have you ever wondered how to efficiently and automatically install software on your Windows machines? With Ansible, you can greatly simplify this process. In this post, I’ll show you how to create a flexible Ansible playbook that can install both MSI and EXE packages.


What is Ansible?

Ansible is an open-source automation tool that helps you manage configurations, deploy applications, and automate many IT tasks. It’s especially useful when you need to perform repetitive operations across multiple servers.


Why Use Ansible for Software Installation on Windows?

With Ansible, you can centrally manage software installations on your Windows machines. This saves time and reduces errors caused by manual installations. You can create Ansible playbooks that precisely define which software should be installed and how it should be configured.


The Playbook: Installing Software on Windows

Here I demonstrate a playbook that can install both MSI and EXE files. You can easily adapt it to your needs by changing the paths and installation parameters.

---
- name: Install software on Windows
  hosts: windows  # Define your target group of Windows hosts
  vars:
    install_type: "msi"  # Set to "msi" or "exe" depending on the file type
    msi_source_path: "/path/to/your/software/file.msi"  # Path to the MSI file on your Ansible server
    msi_dest_path: "C:\\temp\\file.msi"  # Destination path on the Windows machine
    exe_source_path: "/path/to/your/software/file.exe"  # Path to the EXE file on your Ansible server
    exe_dest_path: "C:\\temp\\file.exe"  # Destination path on the Windows machine
    exe_install_params: "/silent /install"  # Installation parameters for the EXE file

  tasks:
    - name: Copy MSI file to Windows machine
      win_copy:
        src: "{{ msi_source_path }}"  # Source MSI file on the Ansible server
        dest: "{{ msi_dest_path }}"    # Destination path on the Windows machine
      when: install_type == "msi"

    - name: Install MSI package
      win_package:
        path: "{{ msi_dest_path }}"   # Path to the copied MSI file
        state: present                # Ensures the package is installed
      when: install_type == "msi"

    - name: Copy EXE file to Windows machine
      win_copy:
        src: "{{ exe_source_path }}"  # Source EXE file
        dest: "{{ exe_dest_path }}"    # Destination path on the Windows machine
      when: install_type == "exe"

    - name: Install EXE package
      win_command: "{{ exe_dest_path }} {{ exe_install_params }}"
      when: install_type == "exe"

Running the Playbook

To run the playbook, specify the installation type. Here are two examples:

MSI Installation

ansible-playbook -i hosts.ini install_software.yml -e install_type=msi

EXE Installation

ansible-playbook -i hosts.ini install_software.yml -e install_type=exe

More Ansible Playbooks

(Space for additional examples or links)


Conclusion

With this flexible Ansible playbook, you can efficiently and automatically install software on your Windows machines. Simply adjust the variables to fit your needs and save valuable time deploying software. Good luck automating!