作者:初初初初丶初崽崽__冏每_472 | 来源:互联网 | 2023-09-02 21:37
----hosts:{{group}} tasks: -name:Autoremovezabbix-agent #UbuntuDebian的软件包安装和管理工具
---
- hosts: "{{ group }}"
tasks:
- name: "Autoremove zabbix-agent"
# Ubuntu/Debian的软件包安装和管理工具
apt:
# 指定软件包名称
name: "zabbix-agent"
# 卸载软件包
state: absent
# 卸载时清理软件包目录
purge: yes
# 任务名称
tags: "remove.agent"
- name: "Download zabbix-release_5.0-1+bionic_all.deb"
# 用于将文件或软件从http、https或ftp下载到本地节点上
get_url:
# 文件的下载地址(网址)
url: "https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb"
# 指定将文件下载的绝对路径
dest: "/tmp/zabbix-release_5.0-1+bionic_all.deb"
tags: "wget.agent"
- name: "dpkg -i zabbix-release_5.0-1+bionic_all.deb"
# Ubuntu/Debian的软件包安装和管理工具
apt:
# 指定.deb后缀的软件包的绝对路径
deb: "/tmp/zabbix-release_5.0-1+bionic_all.deb"
# 安装指定.deb后缀的软件包
state: present
tags: "dpkg.agent"
- name: "Update zabbix-agent"
# Ubuntu/Debian的软件包安装和管理工具
apt:
# 更新软件包版本,不安装
update_cache: yes
- name: "Install zabbix-agent"
# Ubuntu/Debian的软件包安装和管理工具
apt:
# 指定软件包名称
name: "zabbix-agent"
# 安装软件包
state: present
tags: "install.agent"
- name: "Check zabbix-agent version"
# 执行命令
shell: "zabbix_agentd -V | grep 'zabbix_agentd'"
# 定义变量存储返回的结果
register: "zabbix_agentd_version"
tags: "version-agent"
- name: "Restart zabbix-agent"
# 服务管理
service:
name: "zabbix-agent.service"
# 重启服务
state: restarted
# 开机自启
enabled: yes
tags: "restart.agent"
- name: "Show debug msg"
# 显示输出的记过
debug:
msg: "{{ zabbix_agentd_version }}"
tags: "version-agent"
...