community.windows.win_eventlog 模块 – 管理 Windows 事件日志

注意

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

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

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

要在 playbook 中使用它,请指定:community.windows.win_eventlog

概要

  • 允许添加、清除和删除本地 Windows 事件日志,以及在给定事件日志中创建和删除源。还允许指定每个日志和源的设置。

参数

参数

注释

category_file

路径

对于指定的一个或多个源,自定义类别资源文件的路径。

maximum_size

字符串

事件日志的最大大小。

值必须介于 64KB 和 4GB 之间,并且可被 64KB 整除。

大小可以以 KB、MB 或 GB 为单位指定(例如 128KB、16MB、2.5GB)。

message_file

路径

对于指定的一个或多个源,自定义事件消息资源文件的路径。

name

字符串 / 必需

要管理的事件日志的名称。

overflow_action

字符串

日志达到最大大小时要采取的操作。

对于 DoNotOverwrite,将保留所有现有条目,并且不会保留新条目。

对于 OverwriteAsNeeded,每个新条目都会覆盖最旧的条目。

对于 OverwriteOlder,新日志条目将覆盖早于 retention_days 值的条目。

选项

  • "DoNotOverwrite"

  • "OverwriteAsNeeded"

  • "OverwriteOlder"

parameter_file

路径

对于指定的一个或多个源,自定义参数资源文件的路径。

retention_days

整数

事件条目必须保留在日志中的最少天数。

此选项仅在 overflow_actionOverwriteOlder 时使用。

sources

列表 / elements=string

要确保在日志中存在/不存在的一个或多个源的列表。

当指定 category_filemessage_file 和/或 parameter_file 时,这些值将应用于所有源。

state

字符串

日志和/或源的所需状态。

当填充 sources 时,将检查源的状态。

当未填充 sources 时,将检查指定日志本身的状态。

如果 stateclear,则会清除目标日志的事件日志条目。

选项

  • "absent"

  • "clear"

  • "present" ← (默认)

参见

另请参阅

community.windows.win_eventlog_entry

将条目写入 Windows 事件日志。

示例

- name: Add a new event log with two custom sources
  community.windows.win_eventlog:
    name: MyNewLog
    sources:
      - NewLogSource1
      - NewLogSource2
    state: present

- name: Change the category and message resource files used for NewLogSource1
  community.windows.win_eventlog:
    name: MyNewLog
    sources:
      - NewLogSource1
    category_file: C:\NewApp\CustomCategories.dll
    message_file: C:\NewApp\CustomMessages.dll
    state: present

- name: Change the maximum size and overflow action for MyNewLog
  community.windows.win_eventlog:
    name: MyNewLog
    maximum_size: 16MB
    overflow_action: DoNotOverwrite
    state: present

- name: Clear event entries for MyNewLog
  community.windows.win_eventlog:
    name: MyNewLog
    state: clear

- name: Remove NewLogSource2 from MyNewLog
  community.windows.win_eventlog:
    name: MyNewLog
    sources:
      - NewLogSource2
    state: absent

- name: Remove MyNewLog and all remaining sources
  community.windows.win_eventlog:
    name: MyNewLog
    state: absent

返回值

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

描述

条目

整数

事件日志中存在的条目计数。

返回: 成功

示例: 50

存在

布尔值

事件日志是否存在。

返回: 成功

示例: true

maximum_size_kb

整数

日志的最大大小(以 KB 为单位)。

返回: 成功

示例: 512

name

字符串

事件日志的名称。

返回: 总是

示例: "MyNewLog"

overflow_action

字符串

日志达到最大大小时采取的操作。

返回: 成功

示例: "OverwriteOlder"

retention_days

整数

日志中保留条目的最少天数。

返回: 成功

示例: 7

sources

列表 / elements=string

日志当前源的列表。

返回: 成功

示例: ["MyNewLog", "NewLogSource1", "NewLogSource2"]

sources_changed

列表 / elements=string

日志中更改(例如,重新创建、删除)的源的列表;如果没有更改源,则此列表为空。

返回: 总是

示例: ["NewLogSource2"]

作者

  • Andrew Saraceni (@andrewsaraceni)