Skip to content

Commit 33888c2

Browse files
authored
Make sure to remove configuration files that are no longer needed (#121)
* Make sure to remove configuration files that are no longer needed Make sure the role specific configuration file is removed if the instace no longer has the role Do the same for the custom configuration file Fixes: #120 * Add nomad_allow_purge_config with default false to avoid an undesired cleanup
1 parent 48576d9 commit 33888c2

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ The role defines most of its variables in `defaults/main.yml`:
4141
- Allow running the role even if not all instances are connected
4242
- Default value: **no**
4343

44+
### `nomad_allow_purge_config`
45+
- Allow purging obsolete configuration files. For example, remove server configuration if instance is no longer a server
46+
- Default value: **no**
47+
4448
### `nomad_version`
4549

4650
- Nomad version to install

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ nomad_debug: false
2626
## Asserts
2727
nomad_skip_ensure_all_hosts: "{{ lookup('env','NOMAD_SKIP_ENSURE_ALL_HOSTS') | default('false', true) }}"
2828

29+
## Config Purge
30+
nomad_allow_purge_config: "{{ lookup('env','NOMAD_ALLOW_PURGE_CONFIG') | default('false', true) }}"
31+
2932
### Package
3033
nomad_version: "{{ lookup('env','NOMAD_VERSION') | default('0.12.1', true) }}"
3134
nomad_architecture_map:

tasks/main.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@
8989
notify:
9090
- restart nomad
9191

92+
- name: Remove Server configuration
93+
file:
94+
dest: "{{ nomad_config_dir }}/server.hcl"
95+
state: absent
96+
when:
97+
- nomad_allow_purge_config | bool
98+
- not _nomad_node_server | bool
99+
notify:
100+
- restart nomad
101+
92102
- name: Client configuration
93103
template:
94104
src: client.hcl.j2
@@ -101,6 +111,16 @@
101111
notify:
102112
- restart nomad
103113

114+
- name: Remove Client configuration
115+
file:
116+
dest: "{{ nomad_config_dir }}/client.hcl"
117+
state: absent
118+
when:
119+
- nomad_allow_purge_config | bool
120+
- not _nomad_node_client | bool
121+
notify:
122+
- restart nomad
123+
104124
- name: Custom configuration
105125
template:
106126
src: custom.json.j2
@@ -113,6 +133,16 @@
113133
notify:
114134
- restart nomad
115135

136+
- name: Remove custome configuration
137+
file:
138+
dest: "{{ nomad_config_dir }}/custom.json"
139+
state: absent
140+
when:
141+
- nomad_allow_purge_config | bool
142+
- nomad_config_custom is not defined
143+
notify:
144+
- restart nomad
145+
116146
- name: Host volume
117147
include: host_volume.yml
118148

0 commit comments

Comments
 (0)