community.windows.win_inet_proxy 模块 – 管理 WinINet 和 Internet Explorer 的代理设置
注意
此模块是 community.windows 集合 (版本 2.3.0) 的一部分。
如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.windows。
要在 playbook 中使用它,请指定:community.windows.win_inet_proxy。
概要
- 用于设置或删除 Windows INet(包括 Internet Explorer)的代理设置。 
- WinINet 是交互式应用程序通过它提交 Web 请求的框架。 
- 其他应用程序(如 Firefox、Chrome 等)也可以使用代理设置,但没有确定的列表。 
参数
| 参数 | 注释 | 
|---|---|
| 代理配置脚本的 URL。 代理配置脚本通常是具有  省略、设置为 null 或空字符串以删除自动配置 URL。 这对应于连接设置窗口中的复选框“使用自动配置脚本”。 | |
| 是否将 WinINet 配置为通过 Web 代理自动检测  这对应于连接设置窗口中的复选框“自动检测设置”。 选项 
 | |
| 访问时将绕过已设置代理的主机列表。 使用  使用  省略、设置为 null 或空字符串/列表以删除 bypass 列表。 如果设置了此项,则也必须设置 *proxy*。 | |
| 要为其设置代理设置的 IE 连接的名称。 这些是 IE 设置中“拨号和虚拟专用网络”标题下的连接。 省略时,使用默认的 LAN 连接。 | |
| 指定要设置的代理的字符串或字典。 如果设置字符串,则应采用  如果未定义端口,则使用正在使用的协议的默认端口。 如果设置字典,则键应为协议,值应为该协议的主机名和/或端口。 有效的协议是  省略、设置为 null 或空字符串以删除代理设置。 | 
备注
注意
- 这与通过 - netsh命令在 WinHTTP 中设置的代理设置不同。请改用 community.windows.win_http_proxy 模块来管理它。
- 默认情况下,这些设置是按用户设置的,而不是系统范围的。如果您希望将代理应用于所有用户,则必须独立于此模块设置注册表属性。有关更多详细信息,请参阅示例。 
- 如果需要按用户代理设置,请使用 *become* 成为主机上的任何本地用户。无需为此设置密码即可使其工作。 
- 如果代理需要身份验证,请使用 community.windows.win_credential 模块设置凭据。这需要使用 *become*,以便可以访问凭据存储。 
另请参阅
另请参阅
- community.windows.win_http_proxy
- 管理 WinHTTP 的代理设置。 
- community.windows.win_credential
- 管理凭据管理器中的 Windows 凭据。 
示例
# This should be set before running the win_inet_proxy module
- name: Configure IE proxy settings to apply to all users
  ansible.windows.win_regedit:
    path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings
    name: ProxySettingsPerUser
    data: 0
    type: dword
    state: present
# This should be set before running the win_inet_proxy module
- name: Configure IE proxy settings to apply per user
  ansible.windows.win_regedit:
    path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings
    name: ProxySettingsPerUser
    data: 1
    type: dword
    state: present
- name: Configure IE proxy to use auto detected settings without an explicit proxy
  win_inet_proxy:
    auto_detect: true
- name: Configure IE proxy to use auto detected settings with a configuration script
  win_inet_proxy:
    auto_detect: true
    auto_config_url: http://proxy.ansible.com/proxy.pac
- name: Configure IE to use explicit proxy host
  win_inet_proxy:
    auto_detect: true
    proxy: ansible.proxy
- name: Configure IE to use explicit proxy host with port and without auto detection
  win_inet_proxy:
    auto_detect: false
    proxy: ansible.proxy:8080
- name: Configure IE to use a specific proxy per protocol
  win_inet_proxy:
    proxy:
      http: ansible.proxy:8080
      https: ansible.proxy:8443
- name: Configure IE to use a specific proxy per protocol using a string
  win_inet_proxy:
    proxy: http=ansible.proxy:8080;https=ansible.proxy:8443
- name: Set a proxy with a bypass list
  win_inet_proxy:
    proxy: ansible.proxy
    bypass:
      - server1
      - server2
      - <-loopback>
      - <local>
- name: Remove any explicit proxies that are set
  win_inet_proxy:
    proxy: ''
    bypass: ''
# This should be done after setting the IE proxy with win_inet_proxy
- name: Import IE proxy configuration to WinHTTP
  win_http_proxy:
    source: ie
# Explicit credentials can only be set per user and require become to work
- name: Set credential to use for proxy auth
  win_credential:
    name: ansible.proxy  # The name should be the FQDN of the proxy host
    type: generic_password
    username: proxyuser
    secret: proxypass
    state: present
  become: true
  become_user: '{{ ansible_user }}'
  become_method: runas
