community.windows.win_user_profile 模块 – 管理 Windows 用户配置文件。

注意

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

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

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

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

概要

  • 用于在 Windows 主机上创建或删除用户配置文件。

  • 这可用于在用户登录之前创建配置文件,或在删除用户帐户时删除配置文件。

  • 可以为本地或域帐户创建配置文件。

参数

参数

注释

名称

字符串

指定配置文件路径的基本名称。

statepresent 时,此值用于在配置文件目录中的特定路径为 username 创建配置文件。

这不能用于指定配置文件目录之外的路径,而是指定此目录中的文件夹。

如果同一路径下已存在其他用户的配置文件,Windows 将自动附加一个 3 位数的增量数字。

stateabsent 并且未设置 username 时,模块将删除指向由此值派生的配置文件路径的所有配置文件。

如果帐户不再存在但配置文件仍然存在,这将非常有用。

remove_multiple

布尔值

stateabsent 并且 name 的值匹配多个配置文件时,模块将失败。

将此值设置为 yes 以强制模块删除找到的所有配置文件。

选择

  • false ← (默认)

  • true

state

字符串

当设置为 present 时,将确保配置文件存在。

创建配置文件时,必须将 username 选项设置为有效帐户。

当设置为 absent 时,将删除配置文件。

删除配置文件时,必须将 username 设置为有效帐户,或者将 name 设置为配置文件的基本名称。

选择

  • "absent"

  • "present" ← (默认)

username

sid

配置文件的安全标识符 (SID) 的帐户名称。

statepresent 时,必须设置此项,并且必须是有效帐户或有效帐户的 SID。

stateabsent 时,这仍然必须是有效的帐号,但 SID 可以是已删除用户的 SID。

另请参阅

另请参阅

ansible.windows.win_user

管理本地 Windows 用户帐户。

community.windows.win_domain_user

管理 Windows Active Directory 用户帐户。

示例

- name: Create a profile for an account
  community.windows.win_user_profile:
    username: ansible-account
    state: present

- name: Create a profile for an account at C:\Users\ansible
  community.windows.win_user_profile:
    username: ansible-account
    name: ansible
    state: present

- name: Remove a profile for a still valid account
  community.windows.win_user_profile:
    username: ansible-account
    state: absent

- name: Remove a profile for a deleted account
  community.windows.win_user_profile:
    name: ansible
    state: absent

- name: Remove a profile for a deleted account based on the SID
  community.windows.win_user_profile:
    username: S-1-5-21-3233007181-2234767541-1895602582-1305
    state: absent

- name: Remove multiple profiles that exist at the basename path
  community.windows.win_user_profile:
    name: ansible
    state: absent
    remove_multiple: true

返回值

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

描述

路径

字符串

帐户配置文件的完整路径。如果 state=absent 并且未删除任何配置文件,则此值将为空。

返回: 始终

示例: "C:\\Users\\ansible"

作者

  • Jordan Borean (@jborean93)