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

Commit 91da506

Browse files
committed
Settings: Migrate users to new accounts.yml layout.
1 parent 55d3846 commit 91da506

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

roles/settings/tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- name: "Setting: Settings Migrator"
3838
include_tasks: "subtasks/settings_migrator.yml"
3939
with_items:
40+
- "accounts.yml"
4041
- "backup_config.yml"
4142

4243
- name: Initialize empty lists and vars

roles/settings/tasks/subtasks/settings_migrator.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
become_user: "{{ cloudbox_yml.stat.pw_name }}"
2929
when: file_is_encrypted
3030

31+
- name: Settings Migrator | Migrations for 'accounts.yml'
32+
block:
33+
34+
# Move 'user,passwd,domain,email' to 'user' key
35+
- name: Settings Migrator | accounts.yml | Migration 01
36+
include_tasks: "settings_migrator/accounts_yml/migration_01.yml"
37+
38+
# Move 'cloudflare_api_token' to 'cloudflare' key
39+
- name: Settings Migrator | accounts.yml | Migration 02
40+
include_tasks: "settings_migrator/accounts_yml/migration_02.yml"
41+
42+
when: (item == "accounts.yml")
43+
3144
- name: Settings Migrator | Migrations for 'backup_config.yml'
3245
block:
3346

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#########################################################################
2+
# Title: 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: "Settings 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: Settings Migrator | accounts.yml | Migration 01 | Add 'user' key
37+
shell: |
38+
yyq d -i {{ playbook_dir }}/{{ item }} user
39+
yyq w -i {{ playbook_dir }}/{{ item }} user.name {{ user }}
40+
yyq d -i {{ playbook_dir }}/{{ item }} passwd
41+
yyq w -i {{ playbook_dir }}/{{ item }} user.pass {{ passwd }}
42+
yyq d -i {{ playbook_dir }}/{{ item }} domain
43+
yyq w -i {{ playbook_dir }}/{{ item }} user.domain {{ domain }}
44+
yyq d -i {{ playbook_dir }}/{{ item }} email
45+
yyq w -i {{ playbook_dir }}/{{ item }} 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: Settings Migrator | accounts.yml | Migration 01 | Remove 'null' values
51+
replace:
52+
path: "{{ playbook_dir }}/{{ item }}"
53+
regexp: 'null'
54+
replace: ''
55+
owner: "{{ cloudbox_yml.stat.uid }}"
56+
group: "{{ cloudbox_yml.stat.gid }}"
57+
mode: 0664
58+
59+
- name: Settings Migrator | accounts.yml | Migration 01 | Re-import Variables
60+
include_vars: "{{ playbook_dir }}/{{ item }}"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#########################################################################
2+
# Title: Settings Migrator | accounts.yml | Migration 02 #
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 | accounts.yml | Migration 02 | Set variables"
12+
set_fact:
13+
old_settings: "{{ true if not(
14+
(cloudflare_api_token is undefined)
15+
or
16+
(cloudflare_api_token is none)
17+
or
18+
(cloudflare_api_token | trim | length == 0)
19+
)
20+
else false }}"
21+
new_settings: "{{ true if not(
22+
(cloudflare is undefined)
23+
or
24+
(cloudflare is none)
25+
or
26+
(cloudflare | trim | length == 0)
27+
or
28+
(cloudflare.email is undefined)
29+
or
30+
(cloudflare.email is none)
31+
or
32+
(cloudflare.email | trim | length == 0)
33+
or
34+
(cloudflare.api is undefined)
35+
or
36+
(cloudflare.api is none)
37+
or
38+
(cloudflare.api | trim | length == 0)
39+
)
40+
else false }}"
41+
42+
- name: Settings Migrator | accounts.yml | Migration 02 | Add 'cloudflare' key
43+
shell: |
44+
yyq w -i {{ playbook_dir }}/{{ item }} cloudflare.email {{ user.email }}
45+
yyq w -i {{ playbook_dir }}/{{ item }} cloudflare.api {{ cloudflare_api_token }}
46+
yyq d -i {{ playbook_dir }}/{{ item }} cloudflare_api_token
47+
become: yes
48+
become_user: "{{ cloudbox_yml.stat.pw_name }}"
49+
when: (old_settings) and not (new_settings)
50+
51+
- name: Settings Migrator | accounts.yml | Migration 02 | Remove 'null' values
52+
replace:
53+
path: "{{ playbook_dir }}/{{ item }}"
54+
regexp: 'null'
55+
replace: ''
56+
owner: "{{ cloudbox_yml.stat.uid }}"
57+
group: "{{ cloudbox_yml.stat.gid }}"
58+
mode: 0664
59+
60+
- name: Settings Migrator | accounts.yml | Migration 02 | Re-import Variables
61+
include_vars: "{{ playbook_dir }}/{{ item }}"

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,15 @@
5959
become: yes
6060
become_user: "{{ cloudbox_yml.stat.pw_name }}"
6161
when: (old_settings) and not (new_settings)
62+
63+
- name: Settings Migrator | backup_config.yml | Migration 01 | Remove 'null' values
64+
replace:
65+
path: "{{ playbook_dir }}/{{ item }}"
66+
regexp: 'null'
67+
replace: ''
68+
owner: "{{ cloudbox_yml.stat.uid }}"
69+
group: "{{ cloudbox_yml.stat.gid }}"
70+
mode: 0664
71+
72+
- name: Settings Migrator | backup_config.yml | Migration 01 | Re-import Variables
73+
include_vars: "{{ playbook_dir }}/{{ item }}"

0 commit comments

Comments
 (0)