summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Yann Wettengel <niyawe@niyawe.de>2017-03-12 17:55:26 +0100
committerNiklas Yann Wettengel <niyawe@niyawe.de>2017-03-12 17:55:26 +0100
commit28ebbd929bbe90d39b26ce49b340071820e227d8 (patch)
treec5427dcc3f0740dc63fa5d56553861dd2e3ec2a6
added boot-rescue role
-rw-r--r--bootstrap_arch.yml9
-rw-r--r--new_inventory.ini.sample7
-rw-r--r--roles/boot-rescue/tasks/main.yml58
3 files changed, 74 insertions, 0 deletions
diff --git a/bootstrap_arch.yml b/bootstrap_arch.yml
new file mode 100644
index 0000000..28e93eb
--- /dev/null
+++ b/bootstrap_arch.yml
@@ -0,0 +1,9 @@
+---
+- name: reboot vserver into rescue image
+ hosts: new_fastds
+ connection: local
+ gather_facts: no
+ vars:
+ ansible_python_interpreter: /usr/bin/python
+ roles:
+ - role: boot-rescue
diff --git a/new_inventory.ini.sample b/new_inventory.ini.sample
new file mode 100644
index 0000000..0e1e3ea
--- /dev/null
+++ b/new_inventory.ini.sample
@@ -0,0 +1,7 @@
+[new_fastds]
+123.123.123.123 arch_hostname=fastd1
+
+[all:vars]
+hetzner_webservice_username=<hetzner_webservice_username>
+hetzner_webservice_password=<hetzner_webservice_password>
+rescue_authorized_key=<fingerprint of ssh key to use in rescue mode>
diff --git a/roles/boot-rescue/tasks/main.yml b/roles/boot-rescue/tasks/main.yml
new file mode 100644
index 0000000..ad7ff9a
--- /dev/null
+++ b/roles/boot-rescue/tasks/main.yml
@@ -0,0 +1,58 @@
+---
+- name: check rescue mode
+ uri:
+ url: https://robot-ws.your-server.de/boot/{{ inventory_hostname }}/rescue
+ method: GET
+ user: "{{ hetzner_webservice_username }}"
+ password: "{{ hetzner_webservice_password }}"
+ force_basic_auth: yes
+ status_code: 200
+ register: rescue
+
+- name: activate rescue mode
+ when: rescue.json.rescue.active == false
+ uri:
+ url: https://robot-ws.your-server.de/boot/{{ inventory_hostname }}/rescue
+ method: POST
+ user: "{{ hetzner_webservice_username }}"
+ password: "{{ hetzner_webservice_password }}"
+ force_basic_auth: yes
+ body: "os=linux&arch=64&authorized_key={{ rescue_authorized_key }}"
+ status_code: 200
+ HEADER_Content-Type: "application/x-www-form-urlencoded"
+ register: activated
+
+#- debug: var=activated
+
+- name: Execute hardware reset
+ uri:
+ url: https://robot-ws.your-server.de/reset/{{ inventory_hostname }}
+ method: POST
+ user: "{{ hetzner_webservice_username }}"
+ password: "{{ hetzner_webservice_password }}"
+ force_basic_auth: yes
+ body: "type=hw"
+ status_code: 200
+ HEADER_Content-Type: "application/x-www-form-urlencoded"
+ register: reset
+
+- name: remove server from local known_hosts file
+ local_action: shell ssh-keygen -R {{ inventory_hostname }}
+ ignore_errors: true
+
+- name: waiting for server to go down
+ local_action:
+ module: wait_for
+ host: "{{ inventory_hostname }}"
+ port: 22
+ delay: 1
+ timeout: 120
+ state: stopped
+
+- name: waiting for server to come back
+ local_action:
+ module: wait_for
+ host: "{{ inventory_hostname }}"
+ port: 22
+ delay: 1
+ timeout: 120