Issues using Ansible URI module - Getting 401 even when authentication credentials are added

Viewed 1134

I am using Ansible's URI module to call a simple GET endpoint but I am getting a 401 error message as shown below.

enter image description here

Here is the playbook configuration

  - name: Elasticsearch Cluster health Check
    uri:
      url: https://elastichost:9200/_cluster/health?&pretty
      url_password : xxxxxxx
      url_username : xxxxxx
      validate_certs : no
      method: GET
      body_format: json
      force_basic_auth: yes
      return_content: yes
      headers:
         Content-Type: "application/json" 
    register: showhealth
    tags: NonProd

  - name: Show Elasticsearch Health
    debug: var=showhealth  
    tags: NonProd

Any inputs on how to resolve

1 Answers

specific issue with elastic. elastic is secure, you need token or certificate to connect to api.

And ofc, your's user need correct right.

exemple

- name: Create update_user
  uri:
    url: 'uri'
    method: POST
    user: elasticuser
    body_format: json
    headers:
      Content-Type: application/json
    body: '{{ item.body }}'
    client_cert: 'certificate.crt'
    client_key: 'certificate.key'
    password: '{{ elastic_password }}'
    validate_certs: false
    return_content: true
Related