diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-09-08 00:20:46 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-09-08 00:20:46 +0200 |
commit | d4dd2f186ea9c5977ea66d3fcc13da8f1553b9d3 (patch) | |
tree | 390bafa38d0e7a3864da121aa43b5ca7aa4bd719 /roles/cloud/install/tasks/hcloud.yml | |
parent | don't autostart testvm (diff) |
major refactoring for cloud install
Diffstat (limited to 'roles/cloud/install/tasks/hcloud.yml')
-rw-r--r-- | roles/cloud/install/tasks/hcloud.yml | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/roles/cloud/install/tasks/hcloud.yml b/roles/cloud/install/tasks/hcloud.yml new file mode 100644 index 00000000..ca5435b8 --- /dev/null +++ b/roles/cloud/install/tasks/hcloud.yml @@ -0,0 +1,68 @@ +--- +- name: retrieve ssh key ids + uri: + url: "https://api.hetzner.cloud/v1/ssh_keys" + method: GET + headers: + Authorization: "Bearer {{ install_cooked.cloud_credentials.token }}" + status_code: 200 + register: sshkeys + delegate_to: localhost + +- name: retrieve server id and check if rescue mode is already active + uri: + url: "https://api.hetzner.cloud/v1/servers?name={{ inventory_hostname }}" + method: GET + headers: + Authorization: "Bearer {{ install_cooked.cloud_credentials.token }}" + status_code: 200 + register: serverstatus + delegate_to: localhost + +- name: do not continue in check mode + fail: + msg: "can not bootstrap new servers in check mode" + when: ansible_check_mode | bool + check_mode: no + +### TODO: for now we add all ssh keys that are installed for this project - this might not be a good idea! +- name: activate rescue mode + when: not serverstatus.json.servers[0].rescue_enabled + uri: + url: "https://api.hetzner.cloud/v1/servers/{{ serverstatus.json.servers[0].id }}/actions/enable_rescue" + method: POST + body: "{{ {'type': 'linux64', 'ssh_keys': (sshkeys.json.ssh_keys | map(attribute='id') | list) } | to_nice_json }}" + headers: + Authorization: "Bearer {{ install_cooked.cloud_credentials.token }}" + Content-Type: "application/json" + status_code: 201 + delegate_to: localhost + +- name: do a hardware reset + uri: + url: "https://api.hetzner.cloud/v1/servers/{{ serverstatus.json.servers[0].id }}/actions/reset" + method: POST + headers: + Authorization: "Bearer {{ install_cooked.cloud_credentials.token }}" + status_code: 201 + delegate_to: localhost + +### TODO: would be nice to get the SSH host key from robot +- name: completely ignore ssh host keys for now + set_fact: + old_ansible_ssh_extra_args: "{{ ansible_ssh_extra_args | default('') }}" + ansible_ssh_extra_args: "{{ ansible_ssh_extra_args | default('') }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + +- name: wait for rescue system to start up + wait_for_connection: + delay: 30 + timeout: 120 + +- include_tasks: hetzner_installimage.yml + +- name: reboot + shell: sleep 2 && shutdown -r now "triggered by ansible after running installimage" + async: 1 + poll: 0 + ignore_errors: True + changed_when: True |