community.vmware.vmware_host_snmp 模块 – 在 ESXi 主机系统上配置 SNMP

注意

此模块是 community.vmware 集合(版本 5.2.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.vmware

要在 playbook 中使用它,请指定:community.vmware.vmware_host_snmp

概要

  • 此模块可用于配置 ESXi 主机上的嵌入式 SNMP 代理。

参数

参数

注释

cluster_name

字符串

在 community.vmware 3.11.0 中添加

集群的名称。

使用给定集群中的所有主机系统来管理 SNMP 代理。

如果未设置 esxi_hostname,则为必需参数。

community

列表 / 元素=字符串

SNMP 社区字符串列表。

默认值: []

esxi_hostname

列表 / 元素=字符串

在 community.vmware 3.11.0 中添加

要管理 SNMP 代理的 ESXi 主机名列表。

如果未设置 cluster_name,则为必需参数。

hostname

字符串

vSphere vCenter 或 ESXi 服务器的主机名或 IP 地址。

如果未在任务中指定值,则将使用环境变量 VMWARE_HOST 的值。

hw_source

字符串

来自 IPMI 传感器或 CIM 指示的源硬件事件。

嵌入式 SNMP 代理从 IPMI 传感器 sensors 或 CIM 指示 indications 接收硬件事件。

选择

  • "indications" ← (默认)

  • "sensors"

log_level

字符串

Syslog 日志级别。

选择

  • "debug"

  • "info" ← (默认)

  • "warning"

  • "error"

password

别名:pass, pwd

字符串

vSphere vCenter 或 ESXi 服务器的密码。

如果未在任务中指定值,则将使用环境变量 VMWARE_PASSWORD 的值。

port

整数

vSphere vCenter 或 ESXi 服务器的端口号。

如果未在任务中指定值,则将使用环境变量 VMWARE_PORT 的值。

默认值: 443

proxy_host

字符串

将接收所有 HTTPS 请求并转发它们的代理的地址。

格式是主机名或 IP。

如果未在任务中指定值,则将使用环境变量 VMWARE_PROXY_HOST 的值。

proxy_port

整数

将接收所有 HTTPS 请求并转发它们的 HTTP 代理的端口。

如果未在任务中指定值,则将使用环境变量 VMWARE_PROXY_PORT 的值。

send_trap

布尔值

发送测试陷阱以验证配置。

选择

  • false ← (默认)

  • true

snmp_port

整数

SNMP 代理使用的端口。

默认值: 161

state

字符串

启用、禁用或重置 SNMP 代理。

选择

  • "disabled" ← (默认)

  • "enabled"

  • "reset"

sys_contact

字符串

管理系统的系统联系人。

sys_location

字符串

系统位置。

trap_filter

列表 / 元素=字符串

不发送代理的陷阱的陷阱 oids 列表,例如 [ 1.3.6.1.4.1.6876.4.1.1.0, 1.3.6.1.4.1.6876.4.1.1.1 ]

使用值 reset 清除设置。

trap_targets

列表 / 元素=字典

陷阱目标列表。

您需要为每个陷阱目标使用 hostnameportcommunity

默认值: []

username

别名:admin, user

字符串

vSphere vCenter 或 ESXi 服务器的用户名。

如果任务中未指定该值,则将使用环境变量 VMWARE_USER 的值。

validate_certs

布尔值

允许在 SSL 证书无效时进行连接。当证书不可信时,设置为 false

如果任务中未指定该值,则将使用环境变量 VMWARE_VALIDATE_CERTS 的值。

选择

  • false

  • true ← (默认)

注释

注意

  • 如果要清除所有 community strings、陷阱目标或过滤器,则需要重置代理(恢复为出厂默认设置)

  • 尚未实现 SNMP v3 配置

  • 所有模块都需要 API 写入权限,因此在免费的 ESXi 许可证上不受支持。

  • 所有变量和 VMware 对象名称都区分大小写。

示例

- name: Enable and configure SNMP community on standalone ESXi host
  community.vmware.vmware_host_snmp:
    hostname: '{{ esxi_hostname }}'
    username: '{{ esxi_username }}'
    password: '{{ esxi_password }}'
    community: [ test ]
    state: enabled
  delegate_to: localhost

- name: Configure SNMP traps and filters on cluster
  community.vmware.vmware_host_snmp:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    cluster_name: '{{ cluster_name }}'
    community: [ test ]
    trap_targets:
      - hostname: 192.168.1.100
        port: 162
        community: test123
      - hostname: 192.168.1.101
        port: 162
        community: test1234
    trap_filter:
      - 1.3.6.1.4.1.6876.4.1.1.0
      - 1.3.6.1.4.1.6876.4.1.1.1
    state: enabled
  delegate_to: localhost

- name: Enable and configure SNMP system contact and location on simple ESXi host in vCenter
  community.vmware.vmware_host_snmp:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    esxi_hostname: '{{ esxi_hostname }}'
    sys_contact: "[email protected]"
    sys_location: "Austin, USA"
    state: enabled
  delegate_to: localhost

- name: Disable SNMP on standalone ESXi host
  community.vmware.vmware_host_snmp:
    hostname: '{{ esxi_hostname }}'
    username: '{{ esxi_username }}'
    password: '{{ esxi_password }}'
    state: disabled
  delegate_to: localhost

返回值

常见的返回值记录在此处 这里,以下是此模块特有的字段

描述

results

字典

关于主机系统 SNMP 配置的元数据

返回: 总是

示例: {"changed": true, "esx01.example.local": {"changed": true, "community": ["test"], "community_previous": [], "hw_source": "indications", "log_level": "info", "log_level_previous": "warning", "msg": "SNMP 状态、 community 列表、 日志 级别、 系统 联系人 系统 位置 已更改", "port": 161, "state": "enabled", "state_previous": "disabled", "sys_contact_previous": "", "sys_location_previous": "", "trap_filter": null, "trap_targets": []}, "failed": false}

作者

  • Christian Kotte (@ckotte)

  • Alexander Nikitin (@ihumster)