community.vmware.vmware_host_ntp 模块 – 管理 ESXi 主机的 NTP 服务器配置

注意

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

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

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

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

概要

  • 此模块可用于配置、添加或删除 ESXi 主机的 NTP 服务器。

  • 如果未指定 state,则将按精确顺序配置 NTP 服务器。

  • 用户可以指定 ESXi 主机名或集群名。如果是集群名,则会更新所有 ESXi 主机。

参数

参数

注释

cluster_name

字符串

将使用所有主机系统的集群名称。

如果未指定 esxi_hostname,则此参数为必填项。

esxi_hostname

字符串

要使用的主机系统的名称。

如果未指定 cluster_name,则此参数为必填项。

hostname

字符串

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

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

ntp_servers

列表 / 元素=字符串 / 必填

NTP 服务器的 IP 或 FQDN。

此参数接受 NTP 服务器列表。对于多个服务器,请查看示例。

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 的值。

state

字符串

present:添加 NTP 服务器(如果指定的服务器不存在)。否则不执行任何操作。

absent:删除 NTP 服务器(如果指定的服务器存在)。否则不执行任何操作。

如果未指定 state,则将配置指定的 NTP 服务器。

选项

  • "存在"

  • "不存在"

用户名

别名: admin, user

字符串

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

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

validate_certs

布尔值

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

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

选项

  • false

  • true ← (默认)

verbose

布尔值

配置更改的详细输出。

解释是否添加了NTP服务器,删除了NTP服务器,或者NTP服务器序列是否发生了更改。

选项

  • false ← (默认)

  • true

备注

注意

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

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

示例

- name: Configure NTP servers for an ESXi Host
  community.vmware.vmware_host_ntp:
    hostname: vcenter01.example.local
    username: [email protected]
    password: SuperSecretPassword
    esxi_hostname: esx01.example.local
    ntp_servers:
        - 0.pool.ntp.org
        - 1.pool.ntp.org
  delegate_to: localhost

- name: Set NTP servers for all ESXi Host in given Cluster
  community.vmware.vmware_host_ntp:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    cluster_name: '{{ cluster_name }}'
    state: present
    ntp_servers:
        - 0.pool.ntp.org
        - 1.pool.ntp.org
  delegate_to: localhost

- name: Set NTP servers for an ESXi Host
  community.vmware.vmware_host_ntp:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    esxi_hostname: '{{ esxi_hostname }}'
    state: present
    ntp_servers:
        - 0.pool.ntp.org
        - 1.pool.ntp.org
  delegate_to: localhost

- name: Remove NTP servers for an ESXi Host
  community.vmware.vmware_host_ntp:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    esxi_hostname: '{{ esxi_hostname }}'
    state: absent
    ntp_servers:
        - bad.server.ntp.org
  delegate_to: localhost

返回值

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

描述

host_ntp_status

字典

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

返回值: 始终

示例: {"esx01.example.local": {"ntp_servers": ["time3.example.local", "time4.example.local"], "ntp_servers_changed": ["time1.example.local", "time2.example.local", "time3.example.local", "time4.example.local"], "ntp_servers_previous": ["time1.example.local", "time2.example.local"]}, "esx02.example.local": {"ntp_servers_changed": ["time3.example.local"], "ntp_servers_current": ["time1.example.local", "time2.example.local", "time3.example.local"], "ntp_servers_previous": ["time1.example.local", "time2.example.local"], "state": "present"}}

作者

  • Abhijeet Kasurde (@Akasurde)

  • Christian Kotte (@ckotte)