linux-system-roles.timesync

时间同步

ansible-lint.yml ansible-test.yml markdownlint.yml shellcheck.yml tft.yml tft_citest_bad.yml woke.yml

该角色安装和配置NTP和/或PTP实现,用于作为NTP客户端和/或PTP从设备来同步系统时钟与NTP服务器和/或PTP域中的主设备。支持的NTP/PTP实现有chrony、ntp(参考实现)和linuxptp。

警告

该角色会替换被管理主机上给定或检测到的提供者服务的配置。之前的设置将会丢失,即使这些设置未在角色变量中指定(不会尝试保留或合并之前的设置,配置文件会被完全替换)。唯一保留的设置是提供者的选择,如果timesync_ntp_provider未定义(请参阅下面该变量的描述)。

需求

请参见下文。

集合需求

为了管理rpm-ostree系统,该角色需要来自外部集合的模块。使用以下命令安装它们:

ansible-galaxy collection install -vv -r meta/collection-requirements.yml

角色变量

可以传递给该角色的变量如下:

# NTP服务器列表
timesync_ntp_servers:
  - hostname: foo.example.com   # 服务器的主机名或地址
    minpoll: 4                  # 最小轮询间隔(默认6)
    maxpoll: 8                  # 最大轮询间隔(默认10)
    iburst: true                # 启用快速初始同步的标志
                                # (默认false)
    pool: false                 # 表示解析出的每个地址都是单独的NTP服务器的标志
                                # (默认false)
    nts: false                  # 启用网络时间安全(NTS)认证机制的标志
                                # (默认false,仅支持chrony >= 4.0)
    prefer: false               # 标记该源为优先同步的标志
                                # (默认false)
    trust: false                # 标记该源为受信任的标志
                                # (默认false)
    xleave: false               # 启用交错模式的标志(默认false)
    filter: 1                   # 每次时钟更新的NTP测量数
                                # (默认1)

# PTP域列表
timesync_ptp_domains:
  - number: 0                   # PTP域号
    interfaces: [eth0]          # 域中的接口列表
    delay: 0.000010             # 假定的与主设备的最大网络延迟(秒)
                                # (默认100微秒)
    transport: UDPv4            # 网络传输方式:UDPv4、UDPv6、L2
                                # (默认UDPv4)
    udp_ttl: 1                  # UDPv4和UDPv6传输的TTL(默认1)
    hybrid_e2e: false           # 启用单播端到端延迟请求的标志(默认false)

# 启用使用DHCP提供的NTP服务器的标志(默认false)
timesync_dhcp_ntp_servers: false

# 可以通过步进纠正的时钟的最小偏移量(默认取决于NTP/PTP实现:
# chrony 1.0,ntp 0.128,linuxptp 0.00002)。
# 设置为零阈值可禁用所有步进。
timesync_step_threshold: 1.0

# 接受来自NTP服务器的测量的最大根距离
# 设置为0以使用提供者默认值
timesync_max_distance: 0

# 允许时钟同步所需的可选择时间源的最小数量(默认1)
timesync_min_sources: 1

# 应该启用硬件时间戳的接口列表用于NTP(默认空列表)。特别值'*'将启用所有支持的接口的时间戳。
timesync_ntp_hwts_interfaces: ["*"]

# 应安装和配置的NTP软件包的名称。
# 可能值为“chrony”和“ntp”。如果未定义,将配置当前活动或启用的服务。
# 如果没有服务处于活动或启用状态,将选择特定于系统及其版本的软件包。
timesync_ntp_provider: chrony

# 有时管理员可能需要为chrony配置未涵盖的扩展设置。
# `timesync_chrony_custom_settings`允许通过提供设置列表来定义
# chrony.conf文件的自定义设置。例如,
# 进行调试时,可能需要记录测量、统计和跟踪信息。
# 这些信息通常存储在/var/log/chrony目录中。为此,需要定义两个不同的设置(logdir和log),如下:
timesync_chrony_custom_settings:
  - "logdir /var/log/chrony"
  - "log measurements statistics tracking"

# 此变量仅适用于事务更新系统。
# 如果事务更新需要重启,如果将`timesync_transactional_update_reboot_ok`设置为`true`,则角色将继续重启。
# 如果设置为`false`,则角色将通知用户需要重启,允许自定义处理重启需求。
# 如果未设置此变量,则角色将失败以确保重启需求不会被忽视。
# 对于非事务更新系统,此变量将被忽略。
timesync_transactional_update_reboot_ok: true

示例剧本

安装并配置ntp,以便与三个NTP服务器同步系统时钟:

- name: 管理与3个服务器的时间同步
  hosts: targets
  vars:
    timesync_ntp_servers:
      - hostname: foo.example.com
        iburst: true
      - hostname: bar.example.com
        iburst: true
      - hostname: baz.example.com
        iburst: true
  roles:
    - linux-system-roles.timesync

安装并配置linuxptp,以便与PTP域号为0的主设备同步系统时钟,该主设备可通过eth0接口访问:

- name: 管理PTP域0中的时间同步,接口eth0
  hosts: targets
  vars:
    timesync_ptp_domains:
      - number: 0
        interfaces: [eth0]
  roles:
    - linux-system-roles.timesync

安装并配置chrony和linuxptp,以便与多个NTP服务器和PTP域进行高度精确和可靠的同步:

- name: 管理多个NTP服务器和PTP域
  hosts: targets
  vars:
    timesync_ntp_servers:
      - hostname: foo.example.com
        maxpoll: 6
      - hostname: bar.example.com
        maxpoll: 6
      - hostname: baz.example.com
        maxpoll: 6
    timesync_ptp_domains:
      - number: 0
        interfaces: [eth0, eth1]
        transport: L2
        delay: 0.000010
      - number: 1
        interfaces: [eth2]
        transport: UDPv4
        delay: 0.000010
  roles:
    - linux-system-roles.timesync

安装并使用多个NTP服务器和自定义高级设置进行chrony配置:将measurementsstatisticstracking记录到/var/log/chrony

- name: 使用自定义高级设置进行管理
  hosts: targets
  vars:
    timesync_ntp_servers:
      - hostname: foo.example.com
      - hostname: bar.example.com
      - hostname: baz.example.com
    timesync_chrony_custom_settings:
      - "logdir /var/log/chrony"
      - "log measurements statistics tracking"
  roles:
    - linux-system-roles.timesync

rpm-ostree

请参见README-ostree.md

安装
ansible-galaxy install linux-system-roles.timesync
许可证
mit
下载
741.9k