diff --git a/.travis.yml b/.travis.yml
index 382c888..479218f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -28,13 +28,6 @@ jobs:
- python: 2.7
env: ANSIBLE_VERSION==2.7.0
-
-# Install ansible
-# addons:
-# apt:
-# packages:
-# - python-pip
-
branches:
only:
- master
@@ -62,5 +55,5 @@ script:
- yamllint .
- ansible-lint tests/test.yml -vvv
-# notifications:
-# webhooks: https://galaxy.ansible.com/api/v1/notifications/
+notifications:
+ webhooks: https://galaxy.ansible.com/api/v1/notifications/
diff --git a/README.md b/README.md
index cf2f68e..9e3e7cd 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,21 @@
Hetzner Installimage Ansible Role
-
+
-
+
Ansible role for re-installing OS on [Hetzner dedicated servers](https://www.hetzner.com/dedicated-rootserver) using [Hetzner APIs](https://robot.your-server.de/doc/webservice/en.html) and [InstallImage](https://docs.hetzner.com/robot/dedicated-server/operating-systems/installimage/)
@@ -54,6 +57,7 @@ image:
[servers]
1.2.3.4 hostname=node1
node2.example.com
+
```
```yaml
diff --git a/tasks/installimage.yml b/tasks/installimage.yml
index d450c85..afdaf9b 100644
--- a/tasks/installimage.yml
+++ b/tasks/installimage.yml
@@ -1,6 +1,10 @@
---
- name: installimage | lookup for host ip address
- command: getent hosts {{ inventory_hostname }} | cut -d' ' -f1
+ shell: >-
+ set -o pipefail &&
+ getent hosts {{ inventory_hostname }} | cut -d' ' -f1
+ args:
+ executable: /bin/bash
register: host_ip_address
failed_when: host_ip_address.stderr or not host_ip_address.stdout
changed_when: false
@@ -8,18 +12,18 @@
- name: installimage | hostname
block:
- - name: installimage | hostname | check hostname
- assert:
- that: host_ip_address.stdout != inventory_hostname
- quiet: true
- fail_msg: >-
- The hostname must be set in case you are using ip addresses
- as we can't get it from the inventory_hostname_short variable.
- when: not hostname
- - name: installimage | hostname | set hostname fact
- set_fact:
- hostname: "{{ inventory_hostname_short }}"
- when: not hostname
+ - name: installimage | hostname | check hostname
+ assert:
+ that: host_ip_address.stdout != inventory_hostname
+ quiet: true
+ fail_msg: >-
+ The hostname must be set in case you are using ip addresses
+ as we can't get it from the inventory_hostname_short variable.
+ when: not hostname
+ - name: installimage | hostname | set hostname fact
+ set_fact:
+ hostname: "{{ inventory_hostname_short }}"
+ when: not hostname
- name: installimage | image
block:
@@ -76,7 +80,3 @@
reboot:
post_reboot_delay: 20
when: reboot_installimage|bool
-
-- name: installimage | gather facts of installed os
- setup:
- when: reboot_installimage|bool
diff --git a/tasks/rescue.yml b/tasks/rescue.yml
index fbd65ac..9fbbf3e 100644
--- a/tasks/rescue.yml
+++ b/tasks/rescue.yml
@@ -1,7 +1,11 @@
---
# detect ip address of the host which is needed for server reboot
- name: rescue | lookup for host ip address
- command: getent hosts {{ inventory_hostname }} | cut -d' ' -f1
+ shell: >-
+ set -o pipefail &&
+ getent hosts {{ inventory_hostname }} | cut -d' ' -f1
+ args:
+ executable: /bin/bash
register: host_ip_address
failed_when: host_ip_address.stderr or not host_ip_address.stdout
changed_when: false
diff --git a/templates/installimage.j2 b/templates/installimage.j2
index 055ef31..3764369 100644
--- a/templates/installimage.j2
+++ b/templates/installimage.j2
@@ -1,9 +1,9 @@
## ====================
## HARD DISK DRIVE(S):
## ====================
-{% for dev, dev_info in ansible_devices.iteritems() if dev.startswith("sd") %}
-# Onboard: {{ dev_info.model }} {{ dev_info.serial }}
-DRIVE{{ loop.index }} /dev/{{ dev }}
+{% for item in ansible_devices | dict2items if item.key.startswith("sd") %}
+# Onboard: {{ item.value.model }} {{ item.value.serial }}
+DRIVE{{ loop.index }} /dev/{{ item.key }}
{% endfor %}
## ===============
diff --git a/vars/main.yml b/vars/main.yml
index 2f779e8..e96131d 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,6 +1,9 @@
---
ansible_port: 22
ansible_user: root
+# rescue already has python3 installed
+ansible_python_interpreter: python3
+# rescue ssh keys should not polute the existing known_hosts
ansible_ssh_extra_args: >-
-o UserKnownHostsFile=/dev/null
-o StrictHostKeyChecking=no