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

Commit f892eae

Browse files
committed
Settings: Reorganized Role (again) [ansible]
1 parent 959c9d0 commit f892eae

File tree

20 files changed

+368
-343
lines changed

20 files changed

+368
-343
lines changed

roles/pre_tasks/tasks/subtasks/user.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- name: "User | Check if user '{{ user.name }}' exists"
1212
shell: "id -un {{ user.name }} >/dev/null 2>&1;"
1313
register: user_check
14+
changed_when: false
1415
failed_when: user_check.rc > 1
1516

1617
- name: "User | Set user variables when '{{ user.name }}' exists"
@@ -24,6 +25,7 @@
2425
- name: "User | Get 'video' gid"
2526
shell: "getent group video | cut -d: -f3"
2627
register: vgid_lookup
28+
changed_when: false
2729

2830
- name: "User | Set 'uid', 'gid', and 'vgid'"
2931
set_fact:

roles/sanity_check/tasks/sanity_check_tags.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ansible-playbook cloudbox.yml --list-tags 2>&1 | grep "TASK TAGS" \
1919
| cut -d":" -f2 | awk '{sub(/\[/, "")sub(/\]/, "")}1' | sed -e 's/,//g' | xargs -n 1 | sort -u
2020
register: t
21+
changed_when: no
2122
when:
2223
- not continuous_integration
2324
- "'cloudbox_mod' not in playbook_dir"
@@ -32,4 +33,4 @@
3233
when:
3334
- not continuous_integration
3435
- "'cloudbox_' not in playbook_dir"
35-
- "'community' not in playbook_dir"
36+
- "'community' not in playbook_dir"

roles/settings/tasks/main.yml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
11
#########################################################################
22
# Title: Cloudbox: Settings Role #
3-
# Author(s): l3uddz, desimaniac #
3+
# Author(s): desimaniac #
44
# URL: https://github.com/cloudbox/cloudbox #
55
# -- #
66
# Part of the Cloudbox project: https://cloudbox.works #
77
#########################################################################
88
# GNU General Public License v3.0 #
99
#########################################################################
1010
---
11-
- name: "Settings: Start"
11+
- name: "Settings | Start"
1212
include_tasks: "subtasks/start.yml"
1313

14-
- name: "Settings: Ansible Config"
15-
include_tasks: "subtasks/ansible_config.yml"
16-
with_items:
17-
- "ansible.cfg"
14+
- name: "Settings | Main 2"
15+
include_tasks: "main2.yml"
16+
loop: "{{ config_files }}"
17+
loop_control:
18+
loop_var: outer_item
1819

19-
- name: "Setting: Settings Migrator"
20-
include_tasks: "subtasks/settings_migrator.yml"
21-
with_items:
22-
- "accounts.yml"
23-
- "settings.yml"
24-
- "adv_settings.yml"
25-
- "backup_config.yml"
26-
27-
- name: Initialize empty lists and vars
28-
set_fact:
29-
files_updated_successfully: []
30-
files_updated_unsuccessfully: []
31-
exit_is_necessary: false
32-
33-
- name: "Setting: Settings Updater"
34-
include_tasks: "subtasks/settings_updater.yml"
35-
with_items:
36-
- "accounts.yml"
37-
- "settings.yml"
38-
- "adv_settings.yml"
39-
- "backup_config.yml"
40-
41-
- name: "Settings: Finish"
20+
- name: "Settings | Finish"
4221
include_tasks: "subtasks/finish.yml"

roles/settings/tasks/main2.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#########################################################################
2+
# Title: Cloudbox: Settings | Main 2 #
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 | Copy"
12+
include_tasks: "subtasks/copy.yml"
13+
vars:
14+
file: "{{ outer_item }}"
15+
16+
- name: "Settings | Decrypt"
17+
include_tasks: "subtasks/decrypt.yml"
18+
vars:
19+
file: "{{ outer_item }}"
20+
when: (outer_item != "ansible.cfg")
21+
22+
- name: "Settings | Migrator"
23+
include_tasks: "subtasks/migrator.yml"
24+
vars:
25+
file: "{{ outer_item }}"
26+
27+
- name: "Settings | Updater"
28+
include_tasks: "subtasks/updater.yml"
29+
vars:
30+
file: "{{ outer_item }}"
31+
when: (outer_item != "ansible.cfg")
32+
33+
- name: "Settings | Re-encrypt"
34+
include_tasks: "subtasks/reencrypt.yml"
35+
vars:
36+
file: "{{ outer_item }}"
37+
when: (outer_item != "ansible.cfg")

roles/settings/tasks/subtasks/ansible_config.yml

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

roles/settings/tasks/subtasks/settings_migrator/global/migration_01.yml renamed to roles/settings/tasks/subtasks/copy.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#########################################################################
2-
# Title: Settings Migrator | Global | Migration 01 #
2+
# Title: Cloudbox: Settings | Copy #
33
# Author(s): desimaniac #
44
# URL: https://github.com/cloudbox/cloudbox #
55
# -- #
@@ -8,15 +8,17 @@
88
# GNU General Public License v3.0 #
99
#########################################################################
1010
---
11-
- name: Settings Migrator | Global | Migration 01 |
12-
Replace '{% raw -%}{{ user }}{%- endraw %}' with '{% raw -%}{{ user.name }}{%- endraw %}'
13-
replace:
14-
path: "{{ playbook_dir }}/{{ item }}"
15-
regexp: '{% raw -%}{{\s*user\s*}}{%- endraw %}'
16-
replace: '{% raw -%}{{ user.name }}{%- endraw %}'
11+
# Check for config files and import they are missing
12+
- name: "Copy | Check if '{{ file }}' exists"
13+
stat:
14+
path: "{{ playbook_dir }}/{{ file }}"
15+
register: file0
16+
17+
- name: "Copy | Copy '{{ file }}.default' to '{{ file }}'"
18+
copy:
19+
src: "{{ playbook_dir }}/defaults/{{ file }}.default"
20+
dest: "{{ playbook_dir }}/{{ file }}"
1721
owner: "{{ cloudbox_yml.stat.uid }}"
1822
group: "{{ cloudbox_yml.stat.gid }}"
1923
mode: 0664
20-
21-
- name: Settings Migrator | Global | Migration 01 | Re-import Variables
22-
include_vars: "{{ playbook_dir }}/{{ item }}"
24+
when: not file0.stat.exists
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#########################################################################
2+
# Title: Cloudbox: Settings | Decrypt #
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: "Decrypt | Check '{{ file }}' for encryption"
12+
shell: "head -1 {{ playbook_dir }}/{{ file }} | grep -q \\$ANSIBLE_VAULT"
13+
register: encryption_check
14+
ignore_errors: yes
15+
changed_when: no
16+
failed_when: encryption_check.rc > 1
17+
18+
- name: "Decrypt | Set 'file_is_encrypted' variable"
19+
set_fact:
20+
file_is_encrypted: "{{ ((encryption_check.rc == 0) | default(false,true)) }}"
21+
22+
- name: "Decrypt | Decrypt '{{ file }}' when encrypted"
23+
shell: "ansible-vault decrypt {{ playbook_dir }}/{{ file }}"
24+
become: yes
25+
become_user: "{{ cloudbox_yml.stat.pw_name }}"
26+
when: file_is_encrypted

roles/settings/tasks/subtasks/finish.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#########################################################################
2-
# Title: Settings: Finish #
2+
# Title: Cloudbox: Settings | Finish #
33
# Author(s): desimaniac #
44
# URL: https://github.com/cloudbox/cloudbox #
55
# -- #
@@ -8,46 +8,46 @@
88
# GNU General Public License v3.0 #
99
#########################################################################
1010
---
11-
# Exit When settings have been updated
12-
- name: Exit | Display Messages Block
11+
# Exit playbook When settings have been updated
12+
- name: Finish | Display Message
1313
block:
1414

15-
- name: "Exit | Check 'settings-updater.py' for new settings"
15+
- name: "Finish | Check 'settings-updater.py' for new settings"
1616
debug:
1717
msg:
1818
- "The 'settings_updater.py' script updated the following
1919
file{{ files_updated_successfully | pluralize }}: '{{ files_updated_successfully | join(', ') | trim }}'"
2020
- "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'"
21+
- "You can also review the log file: 'settings-updater.log'"
2222
when: files_updated_successfully | length > 0
2323

24-
- name: "Exit | Check 'settings-updater.py' run status for errors"
24+
- name: "Finish | Check 'settings-updater.py' run status for errors"
2525
debug:
2626
msg:
2727
- "The 'settings_updater.py' script exited with an error when updating the following
2828
file{{ files_updated_unsuccessfully | pluralize }}: '{{ files_updated_unsuccessfully | join(', ') | trim }}'"
2929
- "Please check 'settings-updater.log' for details"
3030
when: files_updated_unsuccessfully | length > 0
3131

32-
- name: "Exit | Exit so that user can check updated files and/or 'settings-updater.log'"
32+
- name: "Finish | Exit so that user can check updated files and/or 'settings-updater.log'"
3333
fail:
3434
msg: "Cloudbox Installer will now exit."
3535

3636
when: exit_is_necessary
3737

3838
# Make sure accounts.yml has been filled in by user
39-
- name: "Exit | Get stats on 'accounts.yml' for hash check"
39+
- name: "Finish | Get stats on 'accounts.yml' for hash check"
4040
stat:
4141
path: "{{ playbook_dir }}/accounts.yml"
4242
register: accounts_yml
4343

44-
- name: "Exit | Get stats on 'accounts.yml.default' for hash check"
44+
- name: "Finish | Get stats on 'accounts.yml.default' for hash check"
4545
stat:
4646
path: "{{ playbook_dir }}/defaults/accounts.yml.default"
4747
register: accounts_yml_default
4848

4949
# Sanity Checks
50-
- name: "Exit | Ensure that 'accounts.yml' is configured"
50+
- name: "Finish | Ensure that 'accounts.yml' is configured"
5151
assert:
5252
that:
5353
- accounts_yml.stat.exists
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#########################################################################
2+
# Title: Cloudbox: 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: Migrator | Migrations for all config files
12+
block:
13+
14+
# Replace {{ user }} with {{ user.name }}
15+
- name: Migrator | All | Migration 01
16+
include_tasks: "migrator/all/migration_01.yml"
17+
18+
when: (file != "ansible.cfg")
19+
20+
- name: Migrator | Migrations for 'ansible.cfg'
21+
block:
22+
23+
# Add 'hash_behaviour = merge'
24+
- name: Migrator | 'ansible.cfg' | Migration 01
25+
include_tasks: "migrator/ansible_cfg/migration_01.yml"
26+
27+
when: (file == "ansible.cfg")
28+
29+
- name: Migrator | Migrations for 'accounts.yml'
30+
block:
31+
32+
# Move 'user,passwd,domain,email' to 'user' key
33+
- name: Migrator | 'accounts.yml' | Migration 01
34+
include_tasks: "migrator/accounts_yml/migration_01.yml"
35+
36+
# Move 'cloudflare_api_token' to 'cloudflare' key
37+
- name: Migrator | 'accounts.yml' | Migration 02
38+
include_tasks: "migrator/accounts_yml/migration_02.yml"
39+
40+
when: (file == "accounts.yml")
41+
42+
- name: Migrator | Migrations for 'backup_config.yml'
43+
block:
44+
45+
# Move 'vault_service' to 'restore_service'
46+
- name: Migrator | 'backup_config.yml' | Migration 01
47+
include_tasks: "migrator/backup_config_yml/migration_01.yml"
48+
49+
when: (file == "backup_config.yml")
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
########################################################################################
2+
# Title: Cloudbox: Settings | Migrator | 'accounts.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: "Migrator | 'accounts.yml' | Migration 01 | Set variables"
12+
set_fact:
13+
old_settings: "{{ true if not(
14+
(passwd is undefined)
15+
or
16+
(passwd is none)
17+
or
18+
(passwd | trim | length == 0)
19+
)
20+
else false }}"
21+
new_settings: "{{ true if not(
22+
(user.name is undefined)
23+
or
24+
(user.name is none)
25+
or
26+
(user.name | trim | length == 0)
27+
or
28+
(user.pass is undefined)
29+
or
30+
(user.pass is none)
31+
or
32+
(user.pass | trim | length == 0)
33+
)
34+
else false }}"
35+
36+
- name: Migrator | 'accounts.yml' | Migration 01 | Add 'user' key
37+
shell: |
38+
yyq d -i {{ playbook_dir }}/{{ file }} user
39+
yyq w -i {{ playbook_dir }}/{{ file }} user.name {{ user }}
40+
yyq d -i {{ playbook_dir }}/{{ file }} passwd
41+
yyq w -i {{ playbook_dir }}/{{ file }} user.pass {{ passwd }}
42+
yyq d -i {{ playbook_dir }}/{{ file }} domain
43+
yyq w -i {{ playbook_dir }}/{{ file }} user.domain {{ domain }}
44+
yyq d -i {{ playbook_dir }}/{{ file }} email
45+
yyq w -i {{ playbook_dir }}/{{ file }} user.email {{ email }}
46+
become: yes
47+
become_user: "{{ cloudbox_yml.stat.pw_name }}"
48+
when: (old_settings) and not (new_settings)
49+
50+
- name: Migrator | 'accounts.yml' | Migration 01 | Remove 'null' values
51+
replace:
52+
path: "{{ playbook_dir }}/{{ file }}"
53+
regexp: 'null'
54+
replace: ''
55+
owner: "{{ cloudbox_yml.stat.uid }}"
56+
group: "{{ cloudbox_yml.stat.gid }}"
57+
mode: 0664
58+
59+
- name: Migrator | 'accounts.yml' | Migration 01 | Re-import Variables
60+
include_vars: "{{ playbook_dir }}/{{ file }}"

0 commit comments

Comments
 (0)
X Tutup