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

Commit f8ef5cd

Browse files
committed
Settings: Reorganized Role [ansible]
1 parent 2266209 commit f8ef5cd

File tree

9 files changed

+94
-74
lines changed

9 files changed

+94
-74
lines changed

roles/settings/tasks/main.yml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,8 @@
88
# GNU General Public License v3.0 #
99
#########################################################################
1010
---
11-
- name: "Install ruamel.yaml"
12-
pip:
13-
name: ruamel.yaml
14-
version: 0.15.35
15-
executable: pip3
16-
17-
- name: "Check to see if yyq is installed"
18-
stat:
19-
path: "/usr/local/bin/yyq"
20-
register: yyq_binary
21-
22-
- name: Install yyq
23-
import_role:
24-
name: yyq
25-
when: (not yyq_binary.stat.exists)
26-
27-
- name: "Get 'cloudbox.yml' info."
28-
stat:
29-
path: "{{ playbook_dir }}/cloudbox.yml"
30-
register: cloudbox_yml
11+
- name: "Settings: Start"
12+
include_tasks: "subtasks/start.yml"
3113

3214
- name: "Settings: Ansible Config"
3315
include_tasks: "subtasks/ansible_config.yml"
@@ -56,5 +38,5 @@
5638
- "adv_settings.yml"
5739
- "backup_config.yml"
5840

59-
- name: "Settings: Exit After Changes"
60-
include_tasks: "subtasks/exit.yml"
41+
- name: "Settings: Finish"
42+
include_tasks: "subtasks/finish.yml"

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: "Ansible Config | 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: "Ansible Config | 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: "Ansible Config | 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?=.*'
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#########################################################################
2-
# Title: Settings: Exit After Changes #
2+
# Title: Settings: Finish #
33
# Author(s): desimaniac #
44
# URL: https://github.com/cloudbox/cloudbox #
55
# -- #
@@ -12,37 +12,45 @@
1212
- name: Exit | Display Messages Block
1313
block:
1414

15-
- name: "Exit | Check 'settings-updater.py' for new settings."
15+
- name: "Exit | Check 'settings-updater.py' for new settings"
1616
debug:
17-
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'."
17+
msg:
18+
- "The 'settings_updater.py' script updated the following
19+
file{{ files_updated_successfully | pluralize }}: '{{ files_updated_successfully | join(', ') | trim }}'"
20+
- "Please check {{ files_updated_successfully | pluralize('this file','these files') }} for the newly added settings"
21+
- "You can also review the log file, 'settings-updater.log'"
1822
when: files_updated_successfully | length > 0
1923

20-
- name: "Exit | Check 'settings-updater.py' run status for errors."
24+
- name: "Exit | Check 'settings-updater.py' run status for errors"
2125
debug:
22-
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."
26+
msg:
27+
- "The 'settings_updater.py' script exited with an error when updating the following
28+
file{{ files_updated_unsuccessfully | pluralize }}: '{{ files_updated_unsuccessfully | join(', ') | trim }}'"
29+
- "Please check 'settings-updater.log' for details"
2330
when: files_updated_unsuccessfully | length > 0
2431

25-
- name: "Exit | Exit so that user can check updated files and/or 'settings-updater.log'."
32+
- name: "Exit | Exit so that user can check updated files and/or 'settings-updater.log'"
2633
fail:
2734
msg: "Cloudbox Installer will now exit."
2835

2936
when: exit_is_necessary
3037

3138
# Make sure accounts.yml has been filled in by user
32-
- name: "Exit | Get stats on 'accounts.yml' for hash check."
39+
- name: "Exit | Get stats on 'accounts.yml' for hash check"
3340
stat:
3441
path: "{{ playbook_dir }}/accounts.yml"
3542
register: accounts_yml
3643

37-
- name: "Exit | Get stats on 'accounts.yml.default' for hash check."
44+
- name: "Exit | Get stats on 'accounts.yml.default' for hash check"
3845
stat:
3946
path: "{{ playbook_dir }}/defaults/accounts.yml.default"
4047
register: accounts_yml_default
4148

42-
- name: "Exit | Ensure that 'accounts.yml' is configured."
49+
# Sanity Checks
50+
- name: "Exit | Ensure that 'accounts.yml' is configured"
4351
assert:
4452
that:
4553
- accounts_yml.stat.exists
4654
- accounts_yml.stat.checksum != accounts_yml_default.stat.checksum
4755
- '"{{ user.domain }}" != "testcloudbox.yml"'
48-
msg: "You must configure 'accounts.yml' before running the Cloudbox installer."
56+
msg: "You must configure 'accounts.yml' before running the Cloudbox installer"

roles/settings/tasks/subtasks/settings_migrator.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
block:
1313

1414
# Decryption Tasks
15-
- name: "Settings Migrator | Check '{{ item }}' for encryption."
15+
- name: "Settings Migrator | Check '{{ item }}' for encryption"
1616
shell: "head -1 {{ playbook_dir }}/{{ item }} | grep -q \\$ANSIBLE_VAULT"
1717
register: encryption_check
1818
ignore_errors: yes
1919
failed_when: encryption_check.rc > 1
2020

21-
- name: "Settings Migrator | Set 'file_is_encrypted' variable."
21+
- name: "Settings Migrator | Set 'file_is_encrypted' variable"
2222
set_fact:
2323
file_is_encrypted: "{{ ((encryption_check.rc == 0) | default(false,true)) }}"
2424

25-
- name: "Settings Migrator | Decrypt '{{ item }}' when encrypted."
25+
- name: "Settings Migrator | Decrypt '{{ item }}' when encrypted"
2626
shell: "ansible-vault decrypt {{ playbook_dir }}/{{ item }}"
2727
become: yes
2828
become_user: "{{ cloudbox_yml.stat.pw_name }}"
@@ -39,11 +39,11 @@
3939
block:
4040

4141
# Move 'user,passwd,domain,email' to 'user' key
42-
- name: Settings Migrator | accounts.yml | Migration 01
42+
- name: Settings Migrator | 'accounts.yml' | Migration 01
4343
include_tasks: "settings_migrator/accounts_yml/migration_01.yml"
4444

4545
# Move 'cloudflare_api_token' to 'cloudflare' key
46-
- name: Settings Migrator | accounts.yml | Migration 02
46+
- name: Settings Migrator | 'accounts.yml' | Migration 02
4747
include_tasks: "settings_migrator/accounts_yml/migration_02.yml"
4848

4949
when: (item == "accounts.yml")
@@ -52,13 +52,13 @@
5252
block:
5353

5454
# Move 'vault_service' to 'restore_service'
55-
- name: Settings Migrator | backup_config.yml | Migration 01
55+
- name: Settings Migrator | 'backup_config.yml' | Migration 01
5656
include_tasks: "settings_migrator/backup_config_yml/migration_01.yml"
5757

5858
when: (item == "backup_config.yml")
5959

6060
always:
61-
- name: "Settings Migrator | Re-encrypt '{{ item }}' if previously encrypted."
61+
- name: "Settings Migrator | Re-encrypt '{{ item }}' if previously encrypted"
6262
shell: "ansible-vault encrypt {{ playbook_dir }}/{{ item }}"
6363
become: yes
6464
become_user: "{{ cloudbox_yml.stat.pw_name }}"

roles/settings/tasks/subtasks/settings_migrator/accounts_yml/migration_01.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#########################################################################
2-
# Title: Settings Migrator | accounts.yml | Migration 01 #
2+
# Title: Settings Migrator | 'accounts.yml' | Migration 01 #
33
# Author(s): desimaniac #
44
# URL: https://github.com/cloudbox/cloudbox #
55
# -- #
@@ -8,7 +8,7 @@
88
# GNU General Public License v3.0 #
99
#########################################################################
1010
---
11-
- name: "Settings Migrator | accounts.yml | Migration 01 | Set variables"
11+
- name: "Settings Migrator | 'accounts.yml' | Migration 01 | Set variables"
1212
set_fact:
1313
old_settings: "{{ true if not(
1414
(passwd is undefined)
@@ -33,7 +33,7 @@
3333
)
3434
else false }}"
3535

36-
- name: Settings Migrator | accounts.yml | Migration 01 | Add 'user' key
36+
- name: Settings Migrator | 'accounts.yml' | Migration 01 | Add 'user' key
3737
shell: |
3838
yyq d -i {{ playbook_dir }}/{{ item }} user
3939
yyq w -i {{ playbook_dir }}/{{ item }} user.name {{ user }}
@@ -47,7 +47,7 @@
4747
become_user: "{{ cloudbox_yml.stat.pw_name }}"
4848
when: (old_settings) and not (new_settings)
4949

50-
- name: Settings Migrator | accounts.yml | Migration 01 | Remove 'null' values
50+
- name: Settings Migrator | 'accounts.yml' | Migration 01 | Remove 'null' values
5151
replace:
5252
path: "{{ playbook_dir }}/{{ item }}"
5353
regexp: 'null'
@@ -56,5 +56,5 @@
5656
group: "{{ cloudbox_yml.stat.gid }}"
5757
mode: 0664
5858

59-
- name: Settings Migrator | accounts.yml | Migration 01 | Re-import Variables
59+
- name: Settings Migrator | 'accounts.yml' | Migration 01 | Re-import Variables
6060
include_vars: "{{ playbook_dir }}/{{ item }}"

roles/settings/tasks/subtasks/settings_migrator/accounts_yml/migration_02.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#########################################################################
2-
# Title: Settings Migrator | accounts.yml | Migration 02 #
2+
# Title: Settings Migrator | 'accounts.yml' | Migration 02 #
33
# Author(s): desimaniac #
44
# URL: https://github.com/cloudbox/cloudbox #
55
# -- #
@@ -8,7 +8,7 @@
88
# GNU General Public License v3.0 #
99
#########################################################################
1010
---
11-
- name: "Settings Migrator | accounts.yml | Migration 02 | Set variables"
11+
- name: "Settings Migrator | 'accounts.yml' | Migration 02 | Set variables"
1212
set_fact:
1313
old_settings: "{{ true if not(
1414
(cloudflare_api_token is undefined)
@@ -39,7 +39,7 @@
3939
)
4040
else false }}"
4141

42-
- name: Settings Migrator | accounts.yml | Migration 02 | Add 'cloudflare' key
42+
- name: Settings Migrator | 'accounts.yml' | Migration 02 | Add 'cloudflare' key
4343
shell: |
4444
yyq w -i {{ playbook_dir }}/{{ item }} cloudflare.email {{ user.email }}
4545
yyq w -i {{ playbook_dir }}/{{ item }} cloudflare.api {{ cloudflare_api_token }}
@@ -48,7 +48,7 @@
4848
become_user: "{{ cloudbox_yml.stat.pw_name }}"
4949
when: (old_settings) and not (new_settings)
5050

51-
- name: Settings Migrator | accounts.yml | Migration 02 | Remove 'null' values
51+
- name: Settings Migrator | 'accounts.yml' | Migration 02 | Remove 'null' values
5252
replace:
5353
path: "{{ playbook_dir }}/{{ item }}"
5454
regexp: 'null'
@@ -57,5 +57,5 @@
5757
group: "{{ cloudbox_yml.stat.gid }}"
5858
mode: 0664
5959

60-
- name: Settings Migrator | accounts.yml | Migration 02 | Re-import Variables
60+
- name: Settings Migrator | 'accounts.yml' | Migration 02 | Re-import Variables
6161
include_vars: "{{ playbook_dir }}/{{ item }}"

roles/settings/tasks/subtasks/settings_migrator/backup_config_yml/migration_01.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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-
#########################################################################
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+
###########################################################################
1010
---
11-
- name: "Settings Migrator | backup_config.yml | Migration 01 | Set variables"
11+
- name: "Settings Migrator | 'backup_config.yml' | Migration 01 | Set variables"
1212
set_fact:
1313
old_settings: "{{ true if not(
1414
(vault_service is undefined)
@@ -51,7 +51,7 @@
5151
)
5252
else false }}"
5353

54-
- name: Settings Migrator | backup_config.yml | Migration 01 | Add 'restore_service' key
54+
- name: Settings Migrator | 'backup_config.yml' | Migration 01 | Add 'restore_service' key
5555
shell: |
5656
yyq w -i {{ playbook_dir }}/{{ item }} restore_service.user {{ vault_service.user }}
5757
yyq w -i {{ playbook_dir }}/{{ item }} restore_service.pass {{ vault_service.pass }}
@@ -60,7 +60,7 @@
6060
become_user: "{{ cloudbox_yml.stat.pw_name }}"
6161
when: (old_settings) and not (new_settings)
6262

63-
- name: Settings Migrator | backup_config.yml | Migration 01 | Remove 'null' values
63+
- name: Settings Migrator | 'backup_config.yml' | Migration 01 | Remove 'null' values
6464
replace:
6565
path: "{{ playbook_dir }}/{{ item }}"
6666
regexp: 'null'
@@ -69,5 +69,5 @@
6969
group: "{{ cloudbox_yml.stat.gid }}"
7070
mode: 0664
7171

72-
- name: Settings Migrator | backup_config.yml | Migration 01 | Re-import Variables
72+
- name: Settings Migrator | 'backup_config.yml' | Migration 01 | Re-import Variables
7373
include_vars: "{{ playbook_dir }}/{{ item }}"

roles/settings/tasks/subtasks/settings_updater.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
block:
1313

1414
# Check for and import settings files.
15-
- name: "Settings Updater | Check if '{{ item }}' exists."
15+
- name: "Settings Updater | Check if '{{ item }}' exists"
1616
stat:
1717
path: "{{ playbook_dir }}/{{ item }}"
1818
register: file0
1919

20-
- name: "Copy '{{ item }}.default' to '{{ item }}'."
20+
- name: "Copy '{{ item }}.default' to '{{ item }}'"
2121
copy:
2222
src: "{{ playbook_dir }}/defaults/{{ item }}.default"
2323
dest: "{{ playbook_dir }}/{{ item }}"
@@ -31,17 +31,17 @@
3131
- name: Settings Updater | Decryption Block
3232
block:
3333

34-
- name: "Settings Updater | Check '{{ item }}' for encryption."
34+
- name: "Settings Updater | Check '{{ item }}' for encryption"
3535
shell: "head -1 {{ playbook_dir }}/{{ item }} | grep -q \\$ANSIBLE_VAULT"
3636
register: encryption_check
3737
ignore_errors: yes
3838
failed_when: encryption_check.rc > 1
3939

40-
- name: "Settings Updater | Set 'file_is_encrypted' variable."
40+
- name: "Settings Updater | Set 'file_is_encrypted' variable"
4141
set_fact:
4242
file_is_encrypted: "{{ ((encryption_check.rc == 0) | default(false,true)) }}"
4343

44-
- name: "Settings Updater | Decrypt '{{ item }}' when encrypted."
44+
- name: "Settings Updater | Decrypt '{{ item }}' when encrypted"
4545
shell: "ansible-vault decrypt {{ playbook_dir }}/{{ item }}"
4646
become: yes
4747
become_user: "{{ cloudbox_yml.stat.pw_name }}"
@@ -50,7 +50,7 @@
5050
when: file0.stat.exists
5151

5252
# settings-updater.py tasks
53-
- name: "Settings Updater | Check if 'settings-updater.log' exists."
53+
- name: "Settings Updater | Check if 'settings-updater.log' exists"
5454
stat:
5555
path: "{{ playbook_dir }}/settings-updater.log"
5656
register: settings_updater_log
@@ -64,8 +64,8 @@
6464
mode: 0664
6565
when: (settings_updater_log.stat.exists)
6666

67-
- name: "Settings Updater | Run 'settings-updater.py' for '{{ item }}'."
68-
script: "roles/settings/files/settings-updater.py '{{ playbook_dir }}' 'defaults/{{ item }}.default' '{{ item }}'"
67+
- name: "Settings Updater | Run 'settings-updater.py' for '{{ item }}'"
68+
script: "'roles/settings/files/settings-updater.py' '{{ playbook_dir }}' 'defaults/{{ item }}.default' '{{ item }}'"
6969
become: yes
7070
become_user: "{{ cloudbox_yml.stat.pw_name }}"
7171
register: settings_updater
@@ -88,7 +88,7 @@
8888
when: (settings_updater.rc == 2) or (settings_updater.rc == 1)
8989

9090
always:
91-
- name: "Settings Updater | Re-encrypt '{{ item }}' if previously encrypted."
91+
- name: "Settings Updater | Re-encrypt '{{ item }}' if previously encrypted"
9292
shell: "ansible-vault encrypt {{ playbook_dir }}/{{ item }}"
9393
become: yes
9494
become_user: "{{ cloudbox_yml.stat.pw_name }}"

0 commit comments

Comments
 (0)