1
Development and Code Review / API Wireguard "result": "failed"
« on: October 26, 2022, 12:29:10 pm »
Hello,
I'm trying to create Wireguard users through the OPNsense API.
To automate it I'm using Ansible.
So I run this command to get all the users
Now when I try to create users with the command:
I have not found any information on this error or how to use the API for Wireguard except this https://docs.opnsense.org/development/api/plugins/wireguard.html which is not very helpfull.
When run the curl command
There is nothing to find in any log files, so what am I doing wrong?
Thank you in advance.
I'm trying to create Wireguard users through the OPNsense API.
To automate it I'm using Ansible.
So I run this command to get all the users
Code: [Select]
- name: Get existing users
ansible.builtin.uri:
url: https://{{ fwhost }}/api/wireguard/client/searchClient
method: GET
user: "{{ opnsense_key }}"
password: "{{ opnsense_secret }}"
force_basic_auth: true
validate_certs: false
return_content: false
register: wg
Which is the same asCode: [Select]
curl -k -u {{ opnsense_key }}:{{ opnsense_secret }} https://{{ fwhost }}/api/wireguard/client/searchClient
It is working fine and I get all infos for the users.Now when I try to create users with the command:
Code: [Select]
- name: Create users
ansible.builtin.uri:
url: https://{{ fwhost }}/api/wireguard/client/addClient
method: POST
url_username: "{{ opnsense_key }}"
url_password: "{{ opnsense_secret }}"
force_basic_auth: true
validate_certs: false
return_content: true
headers:
Content-Type: application/json
body_format: json
body:
enabled: true
name: "{{ item.key }}"
pubkey: "{{ keys }}"
tunneladdress: "{{ item.value.tunneladdress }}"
with_dict:
- "{{ wireguard_users }}"
register: result
Then I just get the message: "result": "failed"I have not found any information on this error or how to use the API for Wireguard except this https://docs.opnsense.org/development/api/plugins/wireguard.html which is not very helpfull.
When run the curl command
Code: [Select]
curl -X POST -d '{"enabled”:"1",”name”:”test.user”,“pubkey“:“$key“,“tunneladdress“:“xxx.xxx.xxx.xxx/xx“}' -H "Content-Type: application/json" -k -u $key:$secret https://$IP/api/wireguard/client/addClient
I get the same message {"result":"failed"}.There is nothing to find in any log files, so what am I doing wrong?
Thank you in advance.