windows - 无法在不提供凭据的情况下使用 (win_)uri 模块从 API 检索信息

标签 windows iis ansible

情况

我有一本配置 Windows 服务器的手册。该剧本是从带有 Ansible 的 RHEL 服务器执行的。 RHEL 服务器具有所有必需的 kerberos 配置,并且 Ansible 配置为使用 winrm over HTTP 使用 kerberos 身份验证对 windows 主机。所有这一切都很好,我只 kinit 一次,一切正常。

对于剧本中的一项任务,我需要先从 REST API 检索一些信息。 REST API 托管在使用 IIS 的 Windows 服务器上,并具有 Windows 身份验证。

问题

我想使用 win_uriuri 模块从 REST API 检索信息,但我不想提供凭据。它适用于 (win_)shell 模块,为什么它不适用于 (win_)uri 模块?

剧本

--- 
- name: API Test 
  vars_files: 
    - secret.yml 
  vars: 
    api_url: http://iiswebserver.my.domain/api/item/0 
  hosts: 
    - windowshost.my.domain 
  gather_facts: no 
  #debugger: on_failed 

  tasks: 

    - name: Win Shell 
      win_shell: | 
        Invoke-RestMethod -Method Get -Uri {{ api_url }} -UseDefaultCredentials 
      register: win_shell_get 

    - name: Local Shell 
      shell: | 
        curl --negotiate -u : {{ api_url }} 
      register: shell_get 
      delegate_to: localhost 

    - name: Get API info remote 
      win_uri: 
        url: "{{ api_url }}" 
        method: GET 
        return_content: yes 
        user: "{{ secret_user }}" 
        password: "{{ secret_password }}" 
      #delegate_to: localhost 
      register: api_get 

    - name: Get API info local 
      uri: 
        url: "{{ api_url }}" 
        method: GET 
        return_content: yes 
        #user: "{{ secret_user }}" 
        #password: "{{ secret_password }}" 
        #other: --negotiate 
      delegate_to: localhost 
      register: api_get_local 

什么有效

两个 shell 任务都可以在不输入凭据的情况下正常工作。

什么不起作用

使用 win_uri 模块仅在我传递不需要的凭据时有效。 win_uri 模块在目标主机的系统上下文中执行,由于 shell 命令有效,我假设 win_uri 模块也应该有效。

在本地主机上使用 uri 模块不起作用。我尝试了几种参数组合(那些是注释行),但我似乎无法让它工作。

输出

enter image description here

最佳答案

根据您的输出,您的 iis 设置为使用没有 kerberos 的 ntlm aka windows 身份验证,它在没有 ansible 的服务器上工作的原因是因为您进行了身份验证。 将 iis 设置更改为匿名

关于windows - 无法在不提供凭据的情况下使用 (win_)uri 模块从 API 检索信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55742916/

相关文章:

c++ - 在 Windows 上使用带有 Cxx.jl 的 Julia 中的 boost 库

c++ - 递减原子计数器 - 但 <only> 在一个条件下

python - Scipy 未安装在 Windows 机器上

powershell - 在 Powershell 中启用 IIS 应用程序的身份验证

iis - iis 7 如何生成etags

c# - 从 Windows 服务创建文件/文件夹时的最佳实践

asp.net - Windows 7 IIS 中的自定义错误页面

SSH 正常,但 Ansible 返回 "unreachable"

ansible - 使用 lineinfile 和 blockinfile 编辑文件还是使用模板复制整个文件?

ubuntu - 如果失败,如何强制 ansible 重试 'apt' 任务?