ansible.windows.win_optional_feature 模块 – 管理可选的 Windows 功能

注意

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

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

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

要在 playbook 中使用它,请指定:ansible.windows.win_optional_feature

概要

  • 在非服务器 Windows 上安装或卸载可选的 Windows 功能。

  • 此模块使用 Enable-WindowsOptionalFeatureDisable-WindowsOptionalFeature cmdlet。

参数

参数

注释

include_parent

布尔值

是否启用父功能和父功能的依赖项。

选择

  • false ← (默认)

  • true

name

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

要安装的功能的名称。

这与 Powershell cmdlet 中的 FeatureName 相关。

要列出所有可用的功能,请使用 PowerShell 命令 Get-WindowsOptionalFeature

source

字符串

指定从中安装功能的源。

可以是 {盘符}:\sources\sxs\\{IP}\share\sources\sxs

state

字符串

确保该功能在系统上是“不存在”还是“存在”。

选择

  • "absent"

  • "present" ← (默认)

另请参阅

另请参阅

chocolatey.chocolatey.win_chocolatey

使用 chocolatey 管理软件包。

ansible.windows.win_feature

在 Windows Server 上安装和卸载 Windows 功能。

ansible.windows.win_package

安装/卸载可安装的软件包。

示例

- name: Install .Net 3.5
  ansible.windows.win_optional_feature:
    name: NetFx3
    state: present

- name: Install .Net 3.5 from source
  ansible.windows.win_optional_feature:
    name: NetFx3
    source: \\share01\win10\sources\sxs
    state: present

- name: Install Microsoft Subsystem for Linux
  ansible.windows.win_optional_feature:
    name: Microsoft-Windows-Subsystem-Linux
    state: present
  register: wsl_status

- name: Reboot if installing Linux Subsytem as feature requires it
  ansible.windows.win_reboot:
  when: wsl_status.reboot_required

- name: Install multiple features in one task
  ansible.windows.win_optional_feature:
    name:
      - NetFx3
      - Microsoft-Windows-Subsystem-Linux
    state: present

返回值

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

描述

reboot_required

布尔值

当目标服务器需要重新启动才能完成更新时为 True

返回:成功

示例: true

作者

  • Carson Anderson (@rcanderson23)