[英]Ansible script to uninstall multiple versions of OMS agent
I wanted to do an uninstallation of OMS agent in our Linux machines.我想在我们的 Linux 机器上卸载OMS 代理。 Unfortunately, we do have different OMS agent versions assigned to each machine.
不幸的是,我们确实为每台机器分配了不同的 OMS 代理版本。 I hard coded the version from my Ansible script
我从我的 Ansible 脚本中对版本进行了硬编码
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.它仅适用于具有相同 OMS 代理版本的机器,否则它将失败。
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
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
.可能还有其他人,例如
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
.请注意,您应该使用
become
,而不是在命令中使用sudo
。 Since it is a version reporting task only, you should also use changed_when
and check_mode
.由于它只是一个版本报告任务,您还应该使用
changed_when
和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?有什么理由不能使用选项
--upgrade
或--force
吗?
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.您还可以查看如何解决适用于 Linux 的 Log Analytics 代理的问题,有一个独立的无版本清除脚本可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.