Skip to content

Commit

Permalink
Use more descriptive name name for provisioned.flag file (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkaholic authored Dec 3, 2019
1 parent 7848356 commit 62e4acb
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The following variable can be set optionally, to set the hostname within the het
hetzner_installimage_server_name: __YOUR_SERVER_NAME__

When executing the playbook successfully the role creates a flag file on the respective server under
`/etc/provisioned.flag`. In the beginning of the role it checks if that file exists on the host and skips the further
`/etc/hetzner_installimage_provisioned.flag`. In the beginning of the role it checks if that file exists on the host and skips the further
tasks. That behaviour can be avoided by using the variable **--extra-vars "{ hetzner_installimage_ignore_provisioned_flag: True }"**.
Setting that variable to true will skip checking the flag file.

Expand Down Expand Up @@ -107,12 +107,12 @@ confirmation step will be skipped for that host.
2. Run the hetzner_installimage role
* Install an already provisioned machine
1. Enter the machine
2. Delete /etc/provisioned.flag or set
2. Delete /etc/hetzner_installimage_provisioned.flag or set
3. Run the hetzner_installimage role

If you are sure, you will not accidentally purge a running machine which is already in use, you can directly run the
role with the extra variable **--extra-vars "{ hetzner_installimage_ignore_provisioned_flag: True }"**. This way the
role will not check the machine for an existing `/etc/provisioned.flag` file but will also not prevent the machine from
role will not check the machine for an existing `/etc/hetzner_installimage_provisioned.flag` file but will also not prevent the machine from
being purged accidentally!

## Available images
Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ hetzner_installimage_install_partitions:
- PART /boot ext4 1G
- PART / ext4 all
hetzner_installimage_install_image: Ubuntu-1604-xenial-64-minimal.tar.gz
# prevent reinstallation of running servers with /etc/provisioned.flag file
# prevent reinstallation of running servers with /etc/hetzner_installimage_provisioned.flag file
hetzner_installimage_ignore_provisioned_flag: False
# time to wait before the reboot kicks after requesting hardware reset
hetzner_installimage_reboot_pause: 30
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/tests/test_installimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_installimage_config_file_has_default_config(self, hostname):
@idata(host_generator())
def test_provisioned_flag_file_exists(self, hostname):
host = testinfra.get_host("docker://" + hostname)
f = host.file('/etc/provisioned.flag')
f = host.file('/etc/hetzner_installimage_provisioned.flag')

assert f.exists
assert f.user == 'root'
Expand Down
4 changes: 2 additions & 2 deletions molecule/ignore_provisioned_flag/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
vars:
hetzner_installimage_robot_api_base_url: http://hetzner-robot:3000
tasks:
- name: Add fake provisioned.flag file
raw: echo 'test' > /etc/provisioned.flag # actual difference to default scenario
- name: Add fake hetzner_installimage_provisioned.flag file
raw: echo 'test' > /etc/hetzner_installimage_provisioned.flag # actual difference to default scenario
- name: Include default prepare tasks
include: ../resources/tasks/prepare-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_installimage_config_file_has_default_config(self, hostname):
@idata(host_generator())
def test_provisioned_flag_file_exists(self, hostname):
host = testinfra.get_host("docker://" + hostname)
f = host.file('/etc/provisioned.flag')
f = host.file('/etc/hetzner_installimage_provisioned.flag')

assert f.exists
assert f.user == 'root'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_installimage_config_file_not_exists(self, hostname):
@idata(host_generator())
def test_provisioned_flag_file__not_exists(self, hostname):
host = testinfra.get_host("docker://" + hostname)
f = host.file('/etc/provisioned.flag')
f = host.file('/etc/hetzner_installimage_provisioned.flag')

assert not f.exists

Expand Down
4 changes: 2 additions & 2 deletions molecule/provisioned_flag/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
- name: Prepare
hosts: all
tasks:
- name: Add fake provisioned.flag file
raw: echo 'test' > /etc/provisioned.flag
- name: Add fake hetzner_installimage_provisioned.flag file
raw: echo 'test' > /etc/hetzner_installimage_provisioned.flag
2 changes: 1 addition & 1 deletion molecule/provisioned_flag/tests/test_provisioned_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_installimage_config_file_not_exists(self, hostname):
@idata(host_generator())
def test_provisioned_flag_file_exists(self, hostname):
host = testinfra.get_host("docker://" + hostname)
f = host.file('/etc/provisioned.flag')
f = host.file('/etc/hetzner_installimage_provisioned.flag')

assert f.exists
assert f.user == 'root'
Expand Down
4 changes: 2 additions & 2 deletions tasks/installimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
set_fact:
installimage_cfg_content: "{{ lookup('template', './installimage.j2') }}"

- name: generate provisioned.flag content using the content of the installimage config
- name: generate hetzner_installimage_provisioned.flag content using the content of the installimage config
set_fact:
provisioned_flag_content: "{{ installimage_cfg_content | md5 }}"

- name: create provisioned_flag file
template:
src: provisioned.flag.j2
dest: /etc/provisioned.flag
dest: /etc/hetzner_installimage_provisioned.flag
owner: root
group: root
mode: 0644
Expand Down
6 changes: 3 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
hetzner_installimage_run: false
when: hetzner_installimage_user_confirmations[inventory_hostname] is not defined or hetzner_installimage_user_confirmations[inventory_hostname] != 'y'

- name: Check existence of /etc/provisioned.flag if possible
- name: Check existence of /etc/hetzner_installimage_provisioned.flag if possible
block:
- name: Check existence of /etc/provisioned.flag
- name: Check existence of /etc/hetzner_installimage_provisioned.flag
stat:
path: /etc/provisioned.flag
path: /etc/hetzner_installimage_provisioned.flag
register: hetzner_installimage_provisioned_flag
when: not hetzner_installimage_ignore_provisioned_flag
ignore_errors: yes
Expand Down
6 changes: 5 additions & 1 deletion templates/provisioned.flag.j2
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{{ provisioned_flag_content }}
# DO NOT touch or remove this file unless you know what you are doing! It is created by the hetzner_installimage
# ansible role in order to indicate that this host was provisioned already with an operating system. Removing the file
# will therefor lead to a fresh install of the operating system on the host with all data being wiped.

configmd5: {{ provisioned_flag_content }}

0 comments on commit 62e4acb

Please sign in to comment.