problem using uri module with proxmox api

204 views
Skip to first unread message

Martin Etcheverry

unread,
Sep 16, 2020, 9:45:00 AM9/16/20
to ansible...@googlegroups.com
Hi , i am pretty noob with ansible, i am struggling interacting with proxmox api using the module uri.
I know that exist a proxmox module in ansible , but i need to send keys right after the vm boots , and that is not covered with the proxmox module .
The proxmox api has a node to send keys (yes one by one).Here is the api node doc.https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/sendkey
I am not used to interact with api's so my code could be "mounstruosily wrong".
But i will use any hint/tip.

---
- name: configura
hosts: localhost
connection: local
gather_facts: no

vars:
proxmox_vmid: "501"
proxmox_node : "gallifrey"
proxmox_auth_user: "someuser@pve"
proxmox_auth_password: "somepassword"


tasks:
- name: generaticket
uri:
method: Post
validate_certs: no
body_format: json
body:
{
"username": "{{ proxmox_auth_user}}",
"password": "{{ proxmox_auth_password }}"
}
return_content: yes
headers:
Content-Type: "application/json"
register: ticket

- name: debug ticket
debug:
var: ticket



- name: set fact jsondata
set_fact: jsondata = "{{ ticket.json.data.ticket }}"

- name: set fact jsondata2
set_fact: jsondata2 = "{{ ticket.json.data.CSRFPreventionToken }}"





- name: debug ticket
debug:
msg: "{{ ticket.json.data.ticket }}"

- name: debug CSRFPreventionToken
debug:
msg: "{{ ticket.json.data.CSRFPreventionToken }}"



- name: envia_caracteres
uri:
url: "{{ proxmox_rest_api_url }}/{{ proxmox_node }}/qemu/{{proxmox_vmid}}/sendkey"
validate_certs: no
use_proxy: no
method: PUT
return_content: no
url_username: "{{ proxmox_auth_user}}"
url_password: "{{ ticket.json.data.ticket }}"
body_format: json
body:
' { "key":"kp_enter", "node":"gallifrey","vmid":"501", "CSRFPreventionToken":"{{ ticket.json.data.CSRFPreventionToken }}", "PVEAuthCookie":"{{ ticket.json.data.ticket }}", "username":"{{ proxmox_auth_user}}", "PVEAuthCookie": "{{ ticket.json.data.ticket }}" }'
headers:
Content-Type: "application/json"






As you can see in the body , i am trying anything that pases on my mind .....

And i still receiving a "Status code was 401 and not [200]: HTTP Error 401: No ticket"

I understand that i am doing the request in bad way , but i don't figure out.
Anyone has interacted with proxmox api using uri module?
Thanks in advance!
Martin
--

                  :::
(\(\
                  *: (=
' :') :*        
                  ... (,('')('')....
          mar...@etcheverri.com

           


Reply all
Reply to author
Forward
0 new messages