summaryrefslogtreecommitdiff
path: root/roles/cloud/install/tasks/edis-kvm.yml
blob: b180bd11c61e8e19e9171ed94863d063ed7c1098 (plain) (blame)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
# https://documenter.getpostman.com/view/14802249/TzkyNLMQ#intro

  ## TODO: allow other installer variants
- name: generate host specific installer iso
  delegate_to: localhost
  vars:
    installer_base_path: "{{ global_cache_dir }}/debian-installer"
    installer_keyrings_path: "{{ global_files_dir }}/common/keyrings"
    debian_preseed_poweroff_when_done: yes
  import_role:
    name: installer/debian/iso

- name: upload installer iso to publishing host
  delegate_to: "{{ install.cloud.image_publish.host }}"
  copy:
    src: "{{ iso_install_target_dir }}/{{ install_hostname }}.iso"
    dest: "{{ install.cloud.image_publish.path }}"

- name: generate auth sessions from API
  delegate_to: localhost
  check_mode: no
  uri:
    url: "https://session.edis.at/kvm/v2/get/auth"
    method: POST
    body_format: form-urlencoded
    body:
      email: "{{ install.cloud.credentials.email }}"
      pw: "{{ install.cloud.credentials.password }}"
    status_code: 200
  register: edis_kvm_auth_session_response

- name: make sure server-id is in results
  assert:
    that: install.cloud.id in edis_kvm_auth_session_response.json.data

- name: retrieve auth session for server-id
  set_fact:
    edis_kvm_auth_session: "{{ edis_kvm_auth_session_response.json.data[install.cloud.id] }}"

- name: make sure no iso image is mounted
  delegate_to: localhost
  uri:
    url: "https://{{ edis_kvm_auth_session.api_host }}/kvm/v2/set/umount"
    method: POST
    body_format: form-urlencoded
    body:
      kvm_id: "{{ edis_kvm_auth_session.kvm_id }}"
      signature: "{{ edis_kvm_auth_session.signature }}"
      valid_until: "{{ edis_kvm_auth_session.valid_until }}"
    status_code: 200

- name: download the custom installer image to API host
  delegate_to: localhost
  uri:
    url: "https://{{ edis_kvm_auth_session.api_host }}/kvm/v2/set/download_iso"
    method: POST
    body_format: form-urlencoded
    body:
      kvm_id: "{{ edis_kvm_auth_session.kvm_id }}"
      signature: "{{ edis_kvm_auth_session.signature }}"
      valid_until: "{{ edis_kvm_auth_session.valid_until }}"
      url: "{{ install.cloud.image_publish.base_url }}/{{ install_hostname }}.iso"
    headers:
      Cache-Control: "no-cache"
    status_code: 200

- name: fetch list of isos
  delegate_to: localhost
  uri:
    url: "https://{{ edis_kvm_auth_session.api_host }}/kvm/v2/get/isos"
    method: POST
    body_format: form-urlencoded
    body:
      kvm_id: "{{ edis_kvm_auth_session.kvm_id }}"
      signature: "{{ edis_kvm_auth_session.signature }}"
      valid_until: "{{ edis_kvm_auth_session.valid_until }}"
    status_code: 200
  register: edis_kvm_installer_isos

- name: extract full path of custom iso
  set_fact:
    edis_kvm_custom_iso_fullpath: "{{ edis_kvm_installer_isos.json.data | select('match', '.*/' + install.cloud.id + '.iso') | first }}"

- name: mount and boot from custom iso
  delegate_to: localhost
  uri:
    url: "https://{{ edis_kvm_auth_session.api_host }}/kvm/v2/set/mount"
    method: POST
    body_format: form-urlencoded
    body:
      kvm_id: "{{ edis_kvm_auth_session.kvm_id }}"
      signature: "{{ edis_kvm_auth_session.signature }}"
      valid_until: "{{ edis_kvm_auth_session.valid_until }}"
      iso: "{{ edis_kvm_custom_iso_fullpath }}"
      force_reset: "yes"
    status_code: 200

- name: installing the system
  pause:
    minutes: 3
    prompt: |
      Waiting for the installer to finish. You may watch the progress via the EDIS Managemet interface at

        https://manage.edis.at/whmcs/clientarea.php?action=services

      Just go to the product page of the VM {{ install.cloud.id }} and enable VNC. After that you may use the
      built-in noVNC instance to watch the installer doing its thing.

      The installer will terminate the VM when done and the install process will continue automatically.
      If the installation is done quicker than this you may press ENTER to continue or CTRL-C then A to abort.

- name: wait for installer to shutdown the VM
  delegate_to: localhost
  uri:
    url: "https://{{ edis_kvm_auth_session.api_host }}/kvm/v2/get/power"
    method: POST
    body_format: form-urlencoded
    body:
      kvm_id: "{{ edis_kvm_auth_session.kvm_id }}"
      signature: "{{ edis_kvm_auth_session.signature }}"
      valid_until: "{{ edis_kvm_auth_session.valid_until }}"
  register: edis_kvm_power_state
  until: "edis_kvm_power_state.json.data == 'server powered off'"
  retries: 60
  delay: 5

- name: unmount the installer iso image
  delegate_to: localhost
  uri:
    url: "https://{{ edis_kvm_auth_session.api_host }}/kvm/v2/set/umount"
    method: POST
    body_format: form-urlencoded
    body:
      kvm_id: "{{ edis_kvm_auth_session.kvm_id }}"
      signature: "{{ edis_kvm_auth_session.signature }}"
      valid_until: "{{ edis_kvm_auth_session.valid_until }}"
    status_code: 200

- name: start the newly installed VM
  delegate_to: localhost
  uri:
    url: "https://{{ edis_kvm_auth_session.api_host }}/kvm/v2/set/poweron"
    method: POST
    body_format: form-urlencoded
    body:
      kvm_id: "{{ edis_kvm_auth_session.kvm_id }}"
      signature: "{{ edis_kvm_auth_session.signature }}"
      valid_until: "{{ edis_kvm_auth_session.valid_until }}"
    status_code: 200