-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_gluon_node.yml
124 lines (104 loc) · 3.63 KB
/
new_gluon_node.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
- name: Prefer netcat-openbsd over gnu netcat
apt: pkg=netcat-openbsd
# This is necessary to set the bridge client_bridge for the proxmox statement.
# As the vmid is not known yet, we have to find it out here.
- name: Predict next vmid
command: /usr/bin/pvesh get /cluster/nextid
register: next_vmid
changed_when: False
- name: Generate some variables
set_fact:
gluon_client_mac: "{{ '52:54:00' | community.general.random_mac(seed=inventory_hostname+gluon_hostname) }}"
vmid: "{{ next_vmid.stdout_lines[0] | int }}"
- name: Calculate link-local address
set_fact:
lladdr: "{{ gluon_client_mac | mac2ipv6 }}%vmbr{{ 20000 + (vmid | int)}}"
- name: debug
debug: var=lladdr
- name: Create new VM with minimal options
community.general.proxmox_kvm:
proxmox_default_behavior: no_defaults
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: localhost
name: "{{ gluon_hostname }}"
node: "{{ proxmox_node }}"
format: raw
ide:
ide1: '{{proxmox_storage_group}}:1,format=raw'
net:
net0: 'e1000={{gluon_client_mac}},bridge=vmbr{{ 20000 + (vmid | int) }}'
net1: 'e1000,bridge={{ wan_bridge }}'
register: proxmox_create
- name: Install Gluon Image
when: proxmox_create.changed
block:
- name: Set client_bridge variable
set_fact:
client_bridge: "vmbr{{ 20000 + (vmid | int) }}"
- name: Ensure client_bridge {{ client_bridge }}
include_tasks: ensure_bridge.yml
vars:
bridge_if: "{{ client_bridge }}"
# - name: debug
# debug: var=proxmox_create
# TASK [debug] ****************************
# ok: [mnesia] => {
# "proxmox_create": {
# "changed": true,
# "devices": {
# "ide1": "local-hdd:vm-106-disk-0"
# },
# "failed": false,
# "mac": {},
# "msg": "VM fftestnode1 with vmid 106 deployed",
# "vmid": 106
# }
# }
- name: Store zfs volume in variable zfs_volume
set_fact:
zfs_volume: "{{ proxmox_create.devices.ide1.split(':')[1] }}"
- name: debug
debug: var=zfs_volume
- name: debug
debug: var=zfs_pool
- name: Download Router Image
get_url:
url: "{{ gluon_image_url }}"
dest: /tmp/gluon_image.gz
- name: Unzip to /dev/zvol/{{ zfs_pool }}/{{ zfs_volume }}
shell: "gunzip /tmp/gluon_image.gz -c | dd iflag=fullblock of=/dev/zvol/{{ zfs_pool}}/{{ zfs_volume}} bs=4M"
- name: Start VM
community.general.proxmox_kvm:
proxmox_default_behavior: no_defaults
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_api_password }}"
api_host: localhost
name: "{{ gluon_hostname }}"
node: "{{ proxmox_node }}"
state: started
- name: Configure the Gluon Image
when: proxmox_create.changed
block:
- name: Wait for ssh on node to become reachable
# "nc -z" just connects and closes the connection then.
shell: "while ! nc -z {{ lladdr }} 22; do echo nope; done"
- name: Add new host
add_host:
name: '{{ gluon_hostname }}'
groups:
- gluon_nodes
- openwrt
hostname: "{{ lladdr }}"
ansible_host: "[{{ lladdr }}]"
ansible_user: root
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p mnesia" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
- name: Configure Node
include_tasks: configure_gluon_node.yml
- name: Leave config mode
when: "gluon_leave_config_mode | default(True) | bool"
block:
- name: Reboot
command: reboot
delegate_to: '{{ gluon_hostname }}'