-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb2.yaml
72 lines (62 loc) · 1.77 KB
/
pb2.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
- name: Create VPN instance
hosts: all
become: true
environment:
NOCLOUD_BASE_URL:
INSTANCE_OWNER_ACCOUNT:
INSTANCE_TOKEN:
INSTANCE_UUID:
NOCLOUD_TOKEN:
VPN_PLAN:
VPN_SP:
vars:
json_payload: |
{
"auto_assign": true,
"sp": "{{ VPN_SP }}",
"account": "{{ INSTANCE_OWNER_ACCOUNT }}",
"instance": {
"title": "VPN",
"billing_plan": { "uuid": "{{ VPN_PLAN }}" },
"product": "setup_vpn",
"config": {
"auto_start": false,
"instance": "{{ INSTANCE_UUID }}"
}
}
}
tasks:
- name: Ensure APT package index is updated
apt:
update_cache: yes
- name: Install required packages
ansible.builtin.package:
name: "{{ item }}"
state: present
loop:
- curl
- name: Debug payload
debug:
var: json_payload
- name: Create instance
shell: |
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {{ NOCLOUD_TOKEN }}" \
-d '{{ json_payload | to_json }}' \
{{ NOCLOUD_BASE_URL }}/nocloud.instances.InstancesService/Create
register: curl_result
- name: Debug body
debug:
var: curl_result.stdout
- name: Parse ID from response
set_fact:
response_id: "{{ (curl_result.stdout | from_json).id }}"
- name: Send vpn instance ID to config
shell: |
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {{ INSTANCE_TOKEN }}" \
-d '{ "field": "linked_vpn_instance", "value": "{{ response_id }}" }' \
{{ NOCLOUD_BASE_URL }}/edge/post_config_data
register: curl_result2