Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API call with required survey var fails when called by ansible with jinja2 var #1943

Open
lg-dgo opened this issue Apr 16, 2024 · 0 comments
Labels

Comments

@lg-dgo
Copy link

lg-dgo commented Apr 16, 2024

Semaphore version: v2.9.64

Observed Behavior

"environment" in data for POST API calls to tasks templates (/api/project/{project_id}/tasks) need to be from type string.

Expected Behavior

"environment" in data for POST API calls to tasks templates (/api/project/{project_id}/tasks) should be JSON.

Extra info

I have a task template with a required survey variable "myvar" looks like this in WebGUI:
semaphore_survey

If I want to run this template I will be asked for the survey var. I runs successful. In the request to the semaphore server I can see the request json data:
{"template_id":32,"environment":"{\"myvar\":\"MyValue\"}","project_id":4}
Note: behind "environment" it if a string-formated JSON part.

In WebUI everything works fine (Response code 201).

Now I try to do the same via an API call within an ansible play with "uri" module:

- name: Query Semaphore Task
    uri:
      url: https://semaphore.internal.domain.com/api/project/4/tasks
      method: "POST"
      body_format: "json"
      status_code: 201
      headers:
        Authorization: "Bearer secret_secret_secret"
        Accept: "application/json"
      body:
        template_id: 32
        environment: "{\"myvar\":\"MyValue\"}"

As you can see the survey var (in "environment") needs to be escaped, but it is working (Response code 201).

In the webserver request I investigated I can see the sent json data looks like this:

{"template_id": 32, "environment": "{\"myvar\":\"MyValue\"}"}

The part behind is environment is interpreted as string, not json.

In the next step I want to have a variable for "MyValue" in ansible, so the "environment" line from above (the ansible play) is changed to this:

environment: "{\"myvar\":\"{{ value_var }} \"}"

where the value of variable "value_var" is "MyValue".

I the webserver request I investigated I can see the sent json data looks like this:
{"template_id": 32, "environment": {"myvar": "MyValue"}}
But the response code is 404! It is not working.

jinja2 does something with that, so that the part behind environment is interpreted as json and not as string. And can't be changed. So, if it would be possible to paste JSON in environment and not a string it should work.

@tboerger tboerger added the bug label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: To triage
Development

No branches or pull requests

2 participants