Skip to content

Commit

Permalink
Merge pull request #1 from mariancraciun1983/develop
Browse files Browse the repository at this point in the history
General stability improvment
  • Loading branch information
mariancraciun1983 authored Nov 4, 2020
2 parents c76fa0e + d69eb3f commit e35fa57
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
11 changes: 2 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ jobs:
- python: 2.7
env: ANSIBLE_VERSION==2.7.0


# Install ansible
# addons:
# apt:
# packages:
# - python-pip

branches:
only:
- master
Expand Down Expand Up @@ -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/
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<h1 align="center">Hetzner Installimage Ansible Role</h1>

<br />

<div align="center">
<a href="https://travis-ci.org/mariancraciun1983/ansible-hetzner-installimage">
<img src="https://travis-ci.org/mariancraciun1983/ansible-hetzner-installimage.svg?branch=master" alt="Build Status" />
</a>
<a href="https://galaxy.ansible.com/mariancraciun1983/ansible-hetzner-installimage">
<img src="https://img.shields.io/badge/ansible--galaxy-haproxy-blue.svg" alt="Ansible Galaxy" />
<img src="https://img.shields.io/ansible/role/51609" alt="Ansible Galaxy" />
</a>
<a href="https://galaxy.ansible.com/mariancraciun1983/ansible-hetzner-installimage">
<img src="https://img.shields.io/ansible/quality/51609" alt="Ansible Quality Score" />
</a>
<a href="https://opensource.org/licenses/MIT">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License" />
</a>
</div>

<br />

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/)

Expand Down Expand Up @@ -54,6 +57,7 @@ image:
[servers]
1.2.3.4 hostname=node1
node2.example.com

```

```yaml
Expand Down
34 changes: 17 additions & 17 deletions tasks/installimage.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
---
- 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
delegate_to: localhost

- 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:
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion tasks/rescue.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions templates/installimage.j2
Original file line number Diff line number Diff line change
@@ -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 %}

## ===============
Expand Down
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e35fa57

Please sign in to comment.