Score:0

Ansible trouble while launching an exe through win_command

cn flag

I'm currently writing a playbook about uninstalling Fusion Inventory Agent and then deploy GLPI agent 1.4 on Windows Server 2016-2022. For all the tests i detail below, i use my domain account which has admin rights on any servers.

(I run ansible core 2.12.10 + python 3.9.2 on a Debian 11 freshly upgraded)

  • The Fusion Inventory agent uninstaller registry path is located at "C:\Program Files\FusionInventory-Agent\Uninstall.exe" so if I run it manually from cmd/powershell with /S option i got an Yes/No UAC popup and so uninstall the agent if i press Yes.

  • Now, if I right-click and run as administrator on my cmd/powershell.exe, i can launch "C:\Program Files\FusionInventory-Agent\Uninstall.exe /S" easily without UAC, it's normal.

From an Ansible perspective if i use this following task:

  tasks:
  - name: uninstall fusion inventory agent through cmd
    ansible.windows.win_command: '"C:\Program Files\FusionInventory-Agent\Uninstall.exe" "/S"'
    become: yes
    become_user: my_domain_account
    become_method: runas
    register: fusion_agent_out

It goes like :

Using module file /usr/lib/python3/dist-packages/ansible_collections/ansible/windows/plugins/modules/win_command.ps1
Pipelining is enabled.
<frhd01inp009> ESTABLISH WINRM CONNECTION FOR USER: mydomain_account@my_domain on PORT 5985 TO my_server
EXEC (via pipeline wrapper)
changed: [server_name] => {
    "changed": true,
    "cmd": "\"C:\\Program Files\\FusionInventory-Agent\\Uninstall.exe\" \"/S\"",
    "delta": "0:00:00.468425",
    "end": "2022-11-24 16:32:12.065029",
    "rc": 0,
    "start": "2022-11-24 16:32:11.596603",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "",
    "stdout_lines": []
}

BUT, it actually doesn't uninstall anything, it seems Ansible successfully launch the command but doesn't catch the result.

I also tried different things to check if it changes something (launch powershell.exe within cmd, from psexec ...) but results fails or "changed" but it doesn't launch uninstall.exe as it should be.

From an Ansible perspective, how to handle that kind of uninstallation ?

Best regards

Gael

Score:0
cn flag

Finally i ended up with a different solution: Just created a Windows scheduled task (still using ansible) to launch the uninstaller and option i need, then specify a username, trigger and run it once.

It's a bypass, but works pretty well

I sit in a Tesla and translated this thread with Ai:

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.