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 等,但没有明确的列表。

参数

参数

注释

auto_config_url

字符串

代理配置脚本的 URL。

代理配置脚本通常是 JavaScript 文件,扩展名为 .pac,它实现了 FindProxyForURL(url, host 函数。

省略,设置为 null 或空字符串以删除自动配置 URL。

这对应于连接设置窗口中的复选框*使用自动配置脚本*。

auto_detect

布尔值

是否配置 WinINet 通过 Web 代理自动发现 WPAD 自动检测代理设置。

这对应于连接设置窗口中的复选框*自动检测设置*。

选择

  • false

  • true ←(默认)

bypass

列表 / 元素=字符串

访问时将绕过设置代理的主机列表。

使用 <local> 来匹配不是完全限定域名的主机名。当需要仅使用主机名连接到内联网站点时,这很有用。如果已定义,则这应该是绕过列表中的最后一项。

使用 <-loopback> 来停止通过任何环回地址(如 127.0.0.1localhost 或本地主机名)连接时自动绕过代理。

省略,设置为 null 或空字符串/列表以删除绕过列表。

如果设置了此项,则还必须设置*proxy*。

connection

字符串

要设置代理设置的 IE 连接的名称。

这些是在 IE 设置中*拨号和虚拟专用网络*标题下的连接。

省略时,将使用默认的 LAN 连接。

proxy

任何

一个字符串或字典,指定要设置的代理。

如果设置字符串,则应采用 hostnamehostname:portprotocol=hostname:port 的形式。

如果端口未定义,则使用所用协议的默认端口。

如果设置字典,则键应为协议,值应为该协议的主机名和/或端口。

有效协议为 httphttpsftpsocks

省略,设置为 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

作者

  • Jordan Borean (@jborean93)