0

I am trying to connect to Rally from Ansible. For this I am using uri module and also created an API key from Rally. My task:-

  tasks:

    - name: Get data
      uri:
        url: 'https://rally1.rallydev.com/slm/webservice/v2.0/subscription'
     #   headers:
      #    api_key: "myapikey"
        user: myapikey
        password:
        follow_redirects: all
        return_content: yes
        status_code: 200
        method: GET
      register: get_data

    - debug: var=get_data

But I am still getting error:-

"msg": "Status code was 401 and not [200]: HTTP Error 401: Full authentication is required to access this resource",

Not sure what I am doing wrong.

rocknrollaki
  • 75
  • 1
  • 4
  • 11
  • 1
    Can you authenticate using `curl` on the command line using those credentials? Is the header really named `apikey`? Because that seems unlikely. – larsks May 16 '19 at 20:48
  • Hi, I was trying to open in browser and the page displays using link:- "https://rally1.rallydev.com/slm/webservice/v2.0/subscription?api_key=myapikey" Also I tried with header- api_key, still not successful. – rocknrollaki May 16 '19 at 21:20
  • 1
    In `https://rally1.rallydev.com/slm/webservice/v2.0/subscription?api_key=myapikey`, `api_key` isn't a header. It's a url query parameter. – larsks May 16 '19 at 21:27
  • so, i just checked, in cli from curl, this works:- (curl https://rally1.rallydev.com/slm/webservice/v2.0/subscription -u myapikey:) adding a colon after API key prevent it from asking for a password, not sure how to add this in playbook – rocknrollaki May 16 '19 at 21:35
  • 1
    The colon separates the username from the password: so in your task set `user` to the api key and set `password` to an empty string. – larsks May 16 '19 at 21:44
  • still getting same error, updated my user and password values up in the code – rocknrollaki May 16 '19 at 21:53
  • 1
    You haven't set your password to an empty string. `password: ""` (which means Ansible is sending `None` for your password). – larsks May 16 '19 at 23:32

1 Answers1

0

A simple way to prove that you have access would be to use curl on the command line and then script it via your favourite language to do something similar to the following:

curl --config options.txt

Where options.txt contains:

url https://rally1.rallydev.com/slm/webservice/v2.0/workspace?query=&fetch=true&start=1&pagesize=20

header = "ZSESSIONID: YOURAPIKEY"

You will see that the API key is used in a header variable ZSESSIONID. It works on my machine.....

NotApplicable
  • 251
  • 1
  • 3