3

I am performing the following POST in a Tower server:

http://<my-tower-url>/api/v2/job_templates/10/launch/


Headers:
Content-Type:application/json
Authorization:sometokenhere

And getting back the error:

{"detail":"Authentication credentials were not provided."}

Have also tried the following:

Headers:
Content-Type:application/json
Authorization:Token sometokenhere

as suggested here.

Same happens when passing raw username/password in the POST body as follows (and skipping the Authorization header):

{
    "username": "myusername",
    "password": "mypass",
    "inventory": "inventoryname",
    "verbosity": 0,
    "extra_vars": {
        "var1": "somevar1",
        "var2": "somevar2",
        "var3": "somevar3",
        "var4": "somevar4",
        "var5": "somevar5"
    }
}

Any idea why this is not working?

pkaramol
  • 16,451
  • 43
  • 149
  • 324

2 Answers2

1
Authorization: Bearer <oauth2-token-value>

See here, Section "3. OAuth 2 Token Authentication", part "Curl Example".

0

I ended up using basic auth as follows:

1.create the user which you want to run your ci jobs with

2.perform the following post at the respective CI job:

curl -o /dev/null -s -w \"%{http_code}\n\" -X POST http://<my-tower-url>/api/v2/job_templates/10/launch/ \
                  -H \"authorization: Basic $MY_AUTH_TOKEN\" \
                  -H \"content-type: application/json\" \
                  -d \"@awx_data.json

Where

  • awx_data.json is a file holding the actual POST body
  • MY_AUTH_TOKEN is the tyical base64 encoded username+password of the above user

You can also assign the above result and check it against 201 which is what AWX returns upon successful job creation.

Polling the AWX server to check if the job was successfully finished is another story of course.

Community
  • 1
  • 1
pkaramol
  • 16,451
  • 43
  • 149
  • 324
  • 1
    Hey! Could you please post in your answer the equivalent POST request you'd make in say.. Postman? I'm trying to request a personal token from `/api/v2/users/13/personal_tokens/` but it will only work from the Ansible website. If I try with Postman, sending through the correct username & password in the body, it still says "Authentication credentials were not provided." – Sam Chahine May 30 '18 at 02:22