X Tutup
Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 61c4022

Browse files
committed
Settings: Reorganized Role [ansible]
- Also Misc tweaks to backup_config.yml vault service migration. fix for log commit
1 parent bdfaf38 commit 61c4022

File tree

7 files changed

+143
-129
lines changed

7 files changed

+143
-129
lines changed

roles/settings/tasks/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
register: cloudbox_yml
3131

3232
- name: "Settings: Ansible Config"
33-
include_tasks: "ansible_config.yml"
33+
include_tasks: "subtasks/ansible_config.yml"
3434
with_items:
3535
- "ansible.cfg"
3636

3737
- name: "Setting: Settings Migrator"
38-
include_tasks: "settings_migrator.yml"
38+
include_tasks: "subtasks/settings_migrator.yml"
3939
with_items:
4040
- "backup_config.yml"
4141

@@ -46,12 +46,12 @@
4646
exit_is_necessary: false
4747

4848
- name: "Setting: Settings Updater"
49-
include_tasks: "settings_updater.yml"
49+
include_tasks: "subtasks/settings_updater.yml"
5050
with_items:
5151
- "accounts.yml"
5252
- "settings.yml"
5353
- "adv_settings.yml"
5454
- "backup_config.yml"
5555

5656
- name: "Settings: Exit After Changes"
57-
include_tasks: "exit.yml"
57+
include_tasks: "subtasks/exit.yml"

roles/settings/tasks/settings_migrator.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

roles/settings/tasks/ansible_config.yml renamed to roles/settings/tasks/subtasks/ansible_config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
# GNU General Public License v3.0 #
99
#########################################################################
1010
---
11-
- name: "Check if '{{ item }}' exists."
11+
- name: "Ansible Config | Check if '{{ item }}' exists."
1212
stat:
1313
path: "{{ playbook_dir }}/{{ item }}"
1414
register: file
1515

16-
- name: "Copy '{{ item }}.default' to '{{ item }}'."
16+
- name: "Ansible Config | Copy '{{ item }}.default' to '{{ item }}'."
1717
copy:
1818
src: "{{ playbook_dir }}/defaults/{{ item }}.default"
1919
dest: "{{ playbook_dir }}/{{ item }}"
@@ -23,7 +23,7 @@
2323
force: yes
2424
when: not file.stat.exists
2525

26-
- name: "Add hash_behaviour into '{{ item }}'."
26+
- name: "Ansible Config | Add hash_behaviour into '{{ item }}'."
2727
lineinfile:
2828
path: "{{ playbook_dir }}/{{ item }}"
2929
regexp: '^hash_behaviour\s?=.*'
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,37 @@
99
#########################################################################
1010
---
1111
# Exit When settings have been updated
12-
- block:
12+
- name: Exit | Display Messages Block
13+
block:
1314

14-
- name: "Check 'settings-updater.py' for new settings."
15+
- name: "Exit | Check 'settings-updater.py' for new settings."
1516
debug:
1617
msg: "The 'settings_updater.py' script updated the following file{{ files_updated_successfully | pluralize }}: '{{ files_updated_successfully | join(', ') | trim }}'. Please check {{ files_updated_successfully | pluralize('this file','these files') }} for the newly added settings. You can also review the log file, 'settings-updater.log'."
1718
when: files_updated_successfully | length > 0
1819

19-
- name: "Check 'settings-updater.py' run status for errors."
20+
- name: "Exit | Check 'settings-updater.py' run status for errors."
2021
debug:
2122
msg: "The 'settings_updater.py' script exited with an error when updating the following file{{ files_updated_unsuccessfully | pluralize }}: '{{ files_updated_unsuccessfully | join(', ') | trim }}'. Please check 'settings-updater.log' for details."
2223
when: files_updated_unsuccessfully | length > 0
2324

24-
- name: "Exit so that user can check updated files and/or 'settings-updater.log'."
25+
- name: "Exit | Exit so that user can check updated files and/or 'settings-updater.log'."
2526
fail:
2627
msg: "Cloudbox Installer will now exit."
2728

2829
when: exit_is_necessary
2930

3031
# Make sure accounts.yml has been filled in by user
31-
- name: "Get stats on 'accounts.yml' for hash check."
32+
- name: "Exit | Get stats on 'accounts.yml' for hash check."
3233
stat:
3334
path: "{{ playbook_dir }}/accounts.yml"
3435
register: accounts_yml
3536

36-
- name: "Get stats on 'accounts.yml.default' for hash check."
37+
- name: "Exit | Get stats on 'accounts.yml.default' for hash check."
3738
stat:
3839
path: "{{ playbook_dir }}/defaults/accounts.yml.default"
3940
register: accounts_yml_default
4041

41-
- name: "Ensure that 'accounts.yml' is configured."
42+
- name: "Exit | Ensure that 'accounts.yml' is configured."
4243
assert:
4344
that:
4445
- accounts_yml.stat.exists
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#########################################################################
2+
# Title: Settings: Settings Migrator #
3+
# Author(s): desimaniac #
4+
# URL: https://github.com/cloudbox/cloudbox #
5+
# -- #
6+
# Part of the Cloudbox project: https://cloudbox.works #
7+
#########################################################################
8+
# GNU General Public License v3.0 #
9+
#########################################################################
10+
---
11+
- name: Settings Migrator | Cloudbox Settings Migrator Block
12+
block:
13+
14+
# Decryption Tasks
15+
- name: "Settings Migrator | Check '{{ item }}' for encryption."
16+
shell: "head -1 {{ playbook_dir }}/{{ item }} | grep -q \\$ANSIBLE_VAULT"
17+
register: encryption_check
18+
ignore_errors: yes
19+
failed_when: encryption_check.rc > 1
20+
21+
- name: "Settings Migrator | Set 'file_is_encrypted' variable."
22+
set_fact:
23+
file_is_encrypted: "{{ ((encryption_check.rc == 0) | default(false,true)) }}"
24+
25+
- name: "Settings Migrator | Decrypt '{{ item }}' when encrypted."
26+
shell: "ansible-vault decrypt {{ playbook_dir }}/{{ item }}"
27+
become: yes
28+
become_user: "{{ cloudbox_yml.stat.pw_name }}"
29+
when: file_is_encrypted
30+
31+
- name: Settings Migrator | Migrations for 'backup_config.yml'
32+
block:
33+
34+
# Move 'vault_service' to 'restore_service'
35+
- name: Settings Migrator | backup_config.yml | Migration 01
36+
include_tasks: "settings_migrator/backup_config_yml/migration_01.yml"
37+
38+
when: (item == "backup_config.yml")
39+
40+
always:
41+
- name: "Settings Migrator | Re-encrypt '{{ item }}' if previously encrypted."
42+
shell: "ansible-vault encrypt {{ playbook_dir }}/{{ item }}"
43+
become: yes
44+
become_user: "{{ cloudbox_yml.stat.pw_name }}"
45+
when: file_is_encrypted
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#########################################################################
2+
# Title: Settings Migrator | backup_config.yml | Migration 01 #
3+
# Author(s): desimaniac #
4+
# URL: https://github.com/cloudbox/cloudbox #
5+
# -- #
6+
# Part of the Cloudbox project: https://cloudbox.works #
7+
#########################################################################
8+
# GNU General Public License v3.0 #
9+
#########################################################################
10+
---
11+
- name: "Settings Migrator | backup_config.yml | Migration 01 | Set variables"
12+
set_fact:
13+
old_settings: "{{ true if not(
14+
(vault_service is undefined)
15+
or
16+
(vault_service is none)
17+
or
18+
(vault_service | trim | length == 0)
19+
or
20+
(vault_service.user is undefined)
21+
or
22+
(vault_service.user is none)
23+
or
24+
(vault_service.user | trim | length == 0)
25+
or
26+
(vault_service.pass is undefined)
27+
or
28+
(vault_service.pass is none)
29+
or
30+
(vault_service.pass | trim | length == 0)
31+
)
32+
else false }}"
33+
new_settings: "{{ true if not(
34+
(restore_service is undefined)
35+
or
36+
(restore_service is none)
37+
or
38+
(restore_service | trim | length == 0)
39+
or
40+
(restore_service.user is undefined)
41+
or
42+
(restore_service.user is none)
43+
or
44+
(restore_service.user | trim | length == 0)
45+
or
46+
(restore_service.pass is undefined)
47+
or
48+
(restore_service.pass is none)
49+
or
50+
(restore_service.pass | trim | length == 0)
51+
)
52+
else false }}"
53+
54+
- name: Settings Migrator | backup_config.yml | Migration 01 | Add 'restore_service' key
55+
shell: |
56+
yyq w -i {{ playbook_dir }}/{{ item }} restore_service.user {{ vault_service.user }}
57+
yyq w -i {{ playbook_dir }}/{{ item }} restore_service.pass {{ vault_service.pass }}
58+
yyq d -i {{ playbook_dir }}/{{ item }} vault_service
59+
become: yes
60+
become_user: "{{ cloudbox_yml.stat.pw_name }}"
61+
when: (old_settings) and not (new_settings)

0 commit comments

Comments
 (0)
X Tutup