Score:0

ansible.windows.win_package pass inventory machine details to msi arguments

uz flag

I'm trying to install MSI file with the help of ansible.windows.win_package module
One of the arguments needs to hold the appserver machine name
Trying the following syntax - didn't work (I shrink the arguments list in the following task file example):

- name: Install Server.msi center_primary_dbserver
  ansible.windows.win_package:
    path: c:\r10_files\Server.msi
    arguments:
      ...
      AUTH=WINDOWS
      APPSERVER={{ center_primary_appservers }}
      RABBITSERVER={{ center_qservers.hosts[0] }}
      ... 
      THUMBPRINT={{ cert_thumbprint }}
      SECURED=1
      SQLSERVERNAME={{ inventory_hostname_short }}
      LOG_SIZE=100
      ...
  when: "'center_primary_dbservers' in group_names"

Here, is part of my inventory file:

---
all:
  children:
    root:
      children:
        center:
          children:
            center_primary_appservers:
              hosts:
                vm1.domain.com:
            center_qservers:
              hosts:
                vm2.domain.com:
            center_primary_dbservers:
              hosts:
                vm3.domain.com:

As we can see -
I need to place the value of the center_primary_appserver machine in APPSERVER argument,
and the value of the center_qserver machine in RABBITSERVER argument
For the THUMBPRINT I created a separate task file that it's results are registered with a cert_thumbprint variable, like this:

- name: Import certificate thumbprint
  ansible.windows.win_certificate_store:
    path: "{{ cert_path.files[0].path }}"
    file_type: pkcs12
    password: "FooF!ght3rs"
    store_location: LocalMachine
    key_storage: machine
    state: present
  become: yes
  become_method: runas
  become_user: SYSTEM
  register: cert_thumbprint
  when: "'certificate_autohrities' in group_names"

So, currently, executing this task produces the following error:

{
    "changed": false,
    "invocation": {
        "module_args": {
            "arguments":
            ... 
            THUMBPRINT={'changed': False, 'skipped': True, 
                        'skip_reason': 'Conditional result was False'} 
            RABBIT_PARENT_SERVER=center_qservers.hosts[0] 
            SECURED=1
            SQLSERVERNAME=vm3
            LOG_SIZE=100 
            ...         
           }
        }
    }
}

To sum up the question:
What is the right syntax to:

  • assign in MSI Arguments - registered variable from another task file (in our example: cert_thumbprint)?
  • assign in MSI Arguments - machine varaible from inventory (in our example: center_primary_appservers, center_qservers.hosts[0])?
Semicolon avatar
jo flag
Are you thinking that there only ever going to be one host in the "group" center_primary_appservers? If so - are you sure you need it to be a group?
uz flag
@Semicolon, In this particular lab - only one, In another lab - no. Flexibility is the key here
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.