0

I'm trying to authenticate to a REST API with using NTLM authentication. First I tried uri module but that didn't have support for NTLM. So I installed win_uri because looks like its supporting ntlm https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_uri_module.html#parameter-use_default_credential

However when I use win_uri. Somehow its trying to run commands on localhost using Powershell. I somehow need to seperate connecting to localhost and connecting to REST api part. But not sure how I can do this?


    ---
# playbooks/pki.yaml

- name: Playbook for cert automation
  gather_facts: no
  hosts: localhost
  tasks:
    - name: Get values
      win_uri:
        url: https://{{ api_url }}/SearchRequests
        method: POST
        src: body.json
        body_format: json
        validate_certs: no
        url_username: {{ user }}
        url_password: {{ password }}
        return_content: true

And the result is

PLAY [Playbook for cert automation] ********************************************************************************************************************************

TASK [Get values] **********************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "/bin/sh: 1: powershell: not found\n", "module_stdout": "", "msg": "The module failed to execute correctly, you probably need to set the interpreter.\nSee stdout/stderr for the exact error", "rc": 127}

PLAY RECAP *********************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

4
  • 1
    Is your localhost a windows machine ? I have strong doubts about this as ansible as a controller is only supported on linux/unix and also because, from your above output, the configured shell is sh (which would be rather odd on windows). Anyhow, the win_uri module needs to run on a windows target. Commented Nov 24, 2022 at 16:25
  • Hi, No my ansible controller is a linux machine. I want to use win_uri in order to authenticate api with ntlm authentication.
    – AlperenK
    Commented Nov 29, 2022 at 15:06
  • Well then why are you trying to run win_uri on localhost? I was asking the question above to be sure but this is actually impossible (since localhost which is the controller must be a linux os). You must target a windows machine in your play. Commented Nov 29, 2022 at 15:08
  • any example do you have? if yes please post here so it will be helpfull. Commented Oct 11, 2023 at 14:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.