Ansible – Why Running ansible.windows.win_package Second Time Fails?

ansibleautomationinstallationmsiwindows

I have a product that I can install it first, then update it – meaning to add more feature to my base product

I do it by execute the MSI first time, then going to Add \ Remove Programs and when selecting the product, you can click "Change" and the Installation Wizard would shown up again, allowing you to select and install additional feature in the product

I created 2 ansible roles and playbooks for this mission
First role uses ansible.windows.win_package to install the base product (see below example)

- name: Install Server.msi primary_appserver
  ansible.windows.win_package:
    path: C:\product.msi
    log_path: C:\InstallProduct.log
    arguments:
     ADDLOCAL=DB,Agent
    state: present
  become: true
  become_method: runas
  vars:
    ansible_become_user: "{{ ansible_user }}"
    ansible_become_password: "{{ ansible_password }}"
  when: "'primary_appservers' in group_names"

Second role uses ansible.windows.win_package again with different ADDLOCAL arguments (the additional features):

- name: Install Engine primary_appserver
  ansible.windows.win_package:
    path: C:\product.msi
    log_path: C:\InstallEngine.log
    arguments:
     ADDLOCAL=Engine
    state: present
  become: true
  become_method: runas
  vars:
    ansible_become_user: "{{ ansible_user }}"
    ansible_become_password: "{{ ansible_password }}"
  when: "'primary_appservers' in group_names"

First role is work fine and executes the msi file, The second one – not
If I do those two tasks, with CLI, msiexec /i it's work fine
So, Why it is not working when performing ansible.windows.win_package?

Best Answer

This problem is most probably the state: present parameter, since the package is already present when the task is run. Instead you can use the creates_path or creates_service params to check if it is needed to install the package.

Example:

- name: Install Engine primary_appserver
  ansible.windows.win_package:
    path: C:\product.msi
    log_path: C:\InstallEngine.log
    arguments:
    ADDLOCAL=Engine
    creates_path: "C:\Path\to\product\folder"
  become: true
  become_method: runas
  vars:
    ansible_become_user: "{{ ansible_user }}"
    ansible_become_password: "{{ ansible_password }}"
  when: "'primary_appservers' in group_names"