• 博客
  • Ansible 社区论坛
  • 文档
Ansible Logo
Ansible 社区文档
Ansible

Ansible 入门

  • Ansible 入门
  • 执行环境入门

安装、升级和配置

  • 安装指南
  • Ansible 移植指南

使用 Ansible

  • 构建 Ansible 清单
  • 使用 Ansible 命令行工具
  • 使用 Ansible Playbook
  • 使用 Ansible Vault 保护敏感数据
  • 使用 Ansible 模块和插件
  • 使用 Ansible 集合
  • 在 Windows 和 BSD 上使用 Ansible
  • Ansible 提示和技巧

为 Ansible 做贡献

  • Ansible 社区指南
  • Ansible 集合贡献者指南
  • ansible-core 贡献者指南
  • 高级贡献者指南
  • Ansible 文档样式指南

扩展 Ansible

  • 开发者指南

常见 Ansible 场景

  • 遗留公有云指南

网络自动化

  • 网络入门
  • 网络高级主题
  • 网络开发者指南

Ansible Galaxy

  • Galaxy 用户指南
  • Galaxy 开发者指南

参考 & 附录

  • 集合索引
    • Amazon 命名空间中的集合
    • Ansible 命名空间中的集合
    • Arista 命名空间中的集合
    • Awx 命名空间中的集合
    • Azure 命名空间中的集合
    • Check_point 命名空间中的集合
    • Chocolatey 命名空间中的集合
    • Cisco 命名空间中的集合
    • Cloud 命名空间中的集合
    • Cloudscale_ch 命名空间中的集合
    • Community 命名空间中的集合
      • Community.Aws
      • Community.Ciscosmb
      • Community.Crypto
      • Community.Digitalocean
      • Community.Dns
      • Community.Docker
      • Community.General
        • 描述
        • 沟通
        • 变更日志
        • 指南
        • 云指南
        • 开发者指南
        • 插件索引
      • Community.Grafana
      • Community.Hashi_Vault
      • Community.Hrobot
      • Community.Library_Inventory_Filtering_V1
      • Community.Libvirt
      • Community.Mongodb
      • Community.Mysql
      • Community.Network
      • Community.Okd
      • Community.Postgresql
      • Community.Proxysql
      • Community.Rabbitmq
      • Community.Routeros
      • Community.Sap_Libs
      • Community.Sops
      • Community.Vmware
      • Community.Windows
      • Community.Zabbix
    • Containers 命名空间中的集合
    • Cyberark 命名空间中的集合
    • Dellemc 命名空间中的集合
    • F5networks 命名空间中的集合
    • Fortinet 命名空间中的集合
    • Frr 命名空间中的集合
    • Gluster 命名空间中的集合
    • Google 命名空间中的集合
    • Grafana 命名空间中的集合
    • Hetzner 命名空间中的集合
    • Hpe 命名空间中的集合
    • Ibm 命名空间中的集合
    • Ieisystem 命名空间中的集合
    • Infinidat 命名空间中的集合
    • Infoblox 命名空间中的集合
    • Inspur 命名空间中的集合
    • Junipernetworks 命名空间中的集合
    • Kaytus 命名空间中的集合
    • Kubernetes 命名空间中的集合
    • Kubevirt 命名空间中的集合
    • Lowlydba 命名空间中的集合
    • Mellanox 命名空间中的集合
    • Microsoft 命名空间中的集合
    • Netapp 命名空间中的集合
    • Netapp_eseries 命名空间中的集合
    • Netbox 命名空间中的集合
    • Ngine_io 命名空间中的集合
    • Openstack 命名空间中的集合
    • Openvswitch 命名空间中的集合
    • Ovirt 命名空间中的集合
    • Purestorage 命名空间中的集合
    • Sensu 命名空间中的集合
    • Servicenow 命名空间中的集合
    • Splunk 命名空间中的集合
    • T_systems_mms 命名空间中的集合
    • Telekom_mms 命名空间中的集合
    • Theforeman 命名空间中的集合
    • Vmware 命名空间中的集合
    • Vultr 命名空间中的集合
    • Vyos 命名空间中的集合
    • Wti 命名空间中的集合
  • 所有模块和插件的索引
  • Playbook 关键字
  • 返回值
  • Ansible 配置设置
  • 控制 Ansible 行为方式:优先级规则
  • YAML 语法
  • Python 3 支持
  • 解释器发现
  • 发布和维护
  • 测试策略
  • 健全性测试
  • 常见问题解答
  • 词汇表
  • Ansible 参考:模块实用程序
  • 特殊变量
  • 红帽 Ansible 自动化平台
  • Ansible 自动化中心
  • 记录 Ansible 输出

路线图

  • Ansible 路线图
  • ansible-core 路线图




Ansible
  • 集合索引
  • Community 命名空间中的集合
  • Community.General
  • community.general.nagios 模块 – 执行 Nagios 中与停机和通知相关的常见任务
  • 在 GitHub 上编辑

community.general.nagios 模块 – 执行 Nagios 中与停机和通知相关的常见任务

注意

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

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

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

要在 playbook 中使用它,请指定:community.general.nagios。

  • 概要

  • 参数

  • 属性

  • 示例

概要

  • nagios 模块具有两个基本功能:计划停机时间和切换服务或主机的警报。

  • nagios 模块不是幂等的。

  • 所有操作都需要显式给出 host 参数。在 playbook 中,您可以使用 {{inventory_hostname}} 变量来引用当前运行 playbook 的主机。

  • 您可以通过用逗号分隔来一次指定多个服务,例如 services=httpd,nfs,puppet。

  • 当指定要处理的服务时,有一个特殊的服务值 host,它将处理 *主机本身* 的警报/停机/确认,例如 services=host。此关键字可能不会与其他服务同时给出。**设置主机的警报/停机/确认不会影响其上运行的任何服务的警报/停机/确认。** 要为特定主机上的所有服务安排停机时间,请使用关键字“all”,例如 services=all。

参数

参数

注释

action

字符串 / 必需

要执行的操作。

acknowledge 和 forced_check 操作已在 community.general 1.2.0 中添加。

选择

  • "downtime"

  • "delete_downtime"

  • "enable_alerts"

  • "disable_alerts"

  • "silence"

  • "unsilence"

  • "silence_nagios"

  • "unsilence_nagios"

  • "command"

  • "servicegroup_service_downtime"

  • "servicegroup_host_downtime"

  • "acknowledge"

  • "forced_check"

author

字符串

将停机评论保留为的作者。仅当 action 为 downtime 或 acknowledge 时才使用。

默认值: "Ansible"

cmdfile

字符串

nagios *命令文件*(FIFO 管道)的路径。仅当自动检测失败时才需要。

command

字符串

要发送到 nagios 的原始命令,不应包括提交的时间头或换行符。

使用 command action 时为必需选项。

comment

字符串

当 action 为 downtime 或 acknowledge 时的评论。

默认值: "Scheduling downtime"

host

字符串

在 Nagios 中操作的主机。

minutes

整数

计划停机的时间(分钟)。

仅可与 action=downtime 一起使用。

默认值: 30

servicegroup

字符串

我们要为其设置停机/警报的服务组。

当使用 servicegroup_service_downtime 和 servicegroup_host_downtime action 时,此选项为必填项。

services

别名:service

字符串

要管理停机/警报的服务。使用逗号分隔多个服务。

当 action 是以下值之一时,此选项为必填项: downtime、 acknowledge、 forced_check、 enable_alerts、 disable_alerts。

start

字符串

在 community.general 0.2.0 中添加

停机应该开始的时间,格式为 time_t(自 Unix 纪元以来的秒数)。

属性

属性

支持

描述

check_mode

支持: 无

可以在 check_mode 下运行,并返回更改状态预测,而无需修改目标。

diff_mode

支持: 无

当处于差异模式时,将返回有关已更改(或可能需要在 check_mode 中更改)的详细信息。

示例

- name: Set 30 minutes of apache downtime
  community.general.nagios:
    action: downtime
    minutes: 30
    service: httpd
    host: '{{ inventory_hostname }}'

- name: Schedule an hour of HOST downtime
  community.general.nagios:
    action: downtime
    minutes: 60
    service: host
    host: '{{ inventory_hostname }}'

- name: Schedule an hour of HOST downtime starting at 2019-04-23T02:00:00+00:00
  community.general.nagios:
    action: downtime
    start: 1555984800
    minutes: 60
    service: host
    host: '{{ inventory_hostname }}'

- name: Schedule an hour of HOST downtime, with a comment describing the reason
  community.general.nagios:
    action: downtime
    minutes: 60
    service: host
    host: '{{ inventory_hostname }}'
    comment: Rebuilding machine

- name: Schedule downtime for ALL services on HOST
  community.general.nagios:
    action: downtime
    minutes: 45
    service: all
    host: '{{ inventory_hostname }}'

- name: Schedule downtime for a few services
  community.general.nagios:
    action: downtime
    services: frob,foobar,qeuz
    host: '{{ inventory_hostname }}'

- name: Set 30 minutes downtime for all services in servicegroup foo
  community.general.nagios:
    action: servicegroup_service_downtime
    minutes: 30
    servicegroup: foo
    host: '{{ inventory_hostname }}'

- name: Set 30 minutes downtime for all host in servicegroup foo
  community.general.nagios:
    action: servicegroup_host_downtime
    minutes: 30
    servicegroup: foo
    host: '{{ inventory_hostname }}'

- name: Delete all downtime for a given host
  community.general.nagios:
    action: delete_downtime
    host: '{{ inventory_hostname }}'
    service: all

- name: Delete all downtime for HOST with a particular comment
  community.general.nagios:
    action: delete_downtime
    host: '{{ inventory_hostname }}'
    service: host
    comment: Planned maintenance

- name: Acknowledge an HOST with a particular comment
  community.general.nagios:
    action: acknowledge
    service: host
    host: '{{ inventory_hostname }}'
    comment: 'power outage - see casenr 12345'

- name: Acknowledge an active service problem for the httpd service with a particular comment
  community.general.nagios:
    action: acknowledge
    service: httpd
    host: '{{ inventory_hostname }}'
    comment: 'service crashed - see casenr 12345'

- name: Reset a passive service check for snmp trap
  community.general.nagios:
    action: forced_check
    service: snmp
    host: '{{ inventory_hostname }}'

- name: Force an active service check for the httpd service
  community.general.nagios:
    action: forced_check
    service: httpd
    host: '{{ inventory_hostname }}'

- name: Force an active service check for all services of a particular host
  community.general.nagios:
    action: forced_check
    service: all
    host: '{{ inventory_hostname }}'

- name: Force an active service check for a particular host
  community.general.nagios:
    action: forced_check
    service: host
    host: '{{ inventory_hostname }}'

- name: Enable SMART disk alerts
  community.general.nagios:
    action: enable_alerts
    service: smart
    host: '{{ inventory_hostname }}'

- name: Disable httpd and nfs alerts
  community.general.nagios:
    action: disable_alerts
    service: httpd,nfs
    host: '{{ inventory_hostname }}'

- name: Disable HOST alerts
  community.general.nagios:
    action: disable_alerts
    service: host
    host: '{{ inventory_hostname }}'

- name: Silence ALL alerts
  community.general.nagios:
    action: silence
    host: '{{ inventory_hostname }}'

- name: Unsilence all alerts
  community.general.nagios:
    action: unsilence
    host: '{{ inventory_hostname }}'

- name: Shut up nagios
  community.general.nagios:
    action: silence_nagios

- name: Annoy me negios
  community.general.nagios:
    action: unsilence_nagios

- name: Command something
  community.general.nagios:
    action: command
    command: DISABLE_FAILURE_PREDICTION

作者

  • Tim Bielawa (@tbielawa)

集合链接

  • 问题跟踪器
  • 存储库(源代码)
  • 寻求帮助
  • 提交错误报告
  • 请求功能
  • 沟通
上一个 下一个

© 版权归 Ansible 项目贡献者所有。 最后更新于 2024 年 12 月 19 日。