2

I wanted to do an uninstallation of OMS agent in our Linux machines. Unfortunately, we do have different OMS agent versions assigned to each machine. I hard coded the version from my Ansible script

command: sudo {{ file_path }}/omsagent-1.13.9-0.universal.x64.sh —-purge 

It only works for machine with that same OMS agent version else, it will fail.

I tried adding wildcard syntax, but it is getting an error stating that command not found

stderr: “sudo :/home/filename/omsagent-* : command not found

if I changed my previous command to

command: sudo {{file_path}}/omsagent-*.universal.x64.sh —-purge 
U880D
  • 8,601
  • 6
  • 24
  • 40

1 Answers1

0

Since I do not have this specific agent in place, I can't provide a full tested working example, but some some guidance.

According the package documentation and All bundle operations, the bundle has an option for

  --version-check        Check versions already installed to see if upgradable.

which should provide the installed version. Furthermore any installed agent has an directory with service control script

/opt/microsoft/omsagent/bin/service_control ...

and probably others, like scxadmin --version. By executing one or the other it should be possible to gather the correct installed version of the agent.

- name: Gather installed OMS agent version
  become: true
  become_method: sudo
  shell: 
    cmd: /opt/microsoft/omsagent/bin/service_control status | grep <whatever is necessary to get the version string only>
  register: VERSION
  changed_when: false
  check_mode: false

Please take note that instead of using sudo within the command, you should use become. Since it is a version reporting task only, you should also use changed_when and check_mode.

After the correct version is gathered you use it like

- name: Purge installed OMS agent version
  become: true
  become_method: sudo
  shell: 
    cmd: "omsagent-{{ VERSION }}.universal.x64.sh —-purge"

Is there any reason why the option --upgrade or --force can`t be used?

You may also have a look into How to troubleshoot issues with the Log Analytics agent for Linux, there is a standalone versionless purge script available.

U880D
  • 8,601
  • 6
  • 24
  • 40
  • Thank you for your comments. I am doing uninstallation of OMS agents to my servers which is why I used — purge instead of update – Matapang Ako Jun 08 '22 at 18:56
  • I am getting an error with the command. Aside from “ cmd: /opt/microsoft/omsagent/bin/service_control status | grep ” I think we can also extract omsagent version using this command “rpm -qa | grep omsagent” . However I am getting an error saying /bin/rpm -qa is not a command or not found. Is it possible because oms agent is not installed under root but other directory? – Matapang Ako Jun 08 '22 at 21:06
  • @MatapangAko, regarding "_I am getting an error with the command_" and since I mentioned several commands, can you provide the command together with the error in a new question, probably asked under serverfault or superuser? – U880D Jun 09 '22 at 05:48
  • @MatapangAko, regarding "_I think we can also extract omsagent version using ...`rpm`_", if the package was installed out of native OS package management then it can't report anything from his database regarding this agent. In my answer I've mentioned that the agent package has already his own tool available to report the correct version, as well documentation. Could you take advantage of them? – U880D Jun 09 '22 at 05:52