JS11
(JS)
1
Hello
I need to run the following command using ansible:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" --data '{"title": "My deploy key", "key": "ssh-rsa AAAA...", "can_push": "true"}' "https://gitlab.example.com/api/v4/projects/5/deploy_keys/"
I can do most part of it using the git uri module, but was wondering how I can process the “–data” part of it ?
This is what I have so far:
`
- name: Deploy SSH Key to New Project
uri:
url: “{{ gitlab_api_url }}/projects/{{ new_project_id }}/deploy_keys/”
method: POST
headers:
PRIVATE-TOKEN: “{{ gitlab_private_token }}”
Content-Type: application/json
status_code: 201
`
Many thanks in advance!
Regards
JS
JS11
(JS)
2
Hello
Just wanted to let you know this has now been solved. Did not realise --data could be passed in as the body.
E.g from SO:
curl -k -X POST https://mylink/action -d username=admin
- uri:
url: https://your.form.based.auth.example.com/index.php
method: POST
body: "name=your_username&password=your_password&enter=Sign%20in"
status_code: 302
headers:
Content-Type: "application/x-www-form-urlencoded"
register: login
body
is similar to --data
.
So in my case,
`
curl --request POST --header “PRIVATE-TOKEN: <your_access_token>” --header “Content-Type: application/json” --data ‘{“title”: “My deploy key”, “key”: “ssh-rsa AAAA…”, “can_push”: “true”}’ “https://gitlab.example.com/api/v4/projects/5/deploy_keys/”
`
became this:
`
- name: Deploy SSH Key to New Project
uri:
url: “https://gitlab.example.com/api/v4/projects/5/deploy_keys/”
method: POST
body_format: json
body:
title: “My deploy key”
key: “ssh-rsa AAAA…”
can_push: “true”
headers:
PRIVATE-TOKEN: “{{ gitlab_private_token }}”
Content-Type: application/json
status_code: 201
`
Regards
Jinal