diff --git a/roles/common/tasks/kernel.yml b/roles/common/tasks/kernel.yml index 1a4aeae..249292c 100644 --- a/roles/common/tasks/kernel.yml +++ b/roles/common/tasks/kernel.yml @@ -27,17 +27,20 @@ - apt-transport-https - ca-certificates state: present + update_cache: true - name: "Common | Kernel | Ensure additional dependencies are installed (on Ubuntu < 20.04 and any other systems)" apt: name: gnupg2 state: present + update_cache: true when: ansible_distribution != 'Ubuntu' or ansible_distribution_version is version('20.04', '<') - name: "Common | Kernel | Ensure additional dependencies are installed (on Ubuntu >= 20.04)" apt: name: gnupg state: present + update_cache: true when: ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '>=') diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 6789a29..035161e 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -16,18 +16,21 @@ - apt-transport-https - ca-certificates state: present + update_cache: true when: docker_add_repo | bool - name: "Docker | Ensure additional dependencies are installed (on Ubuntu < 20.04 and any other systems)." apt: name: gnupg2 state: present + update_cache: true when: ansible_distribution != 'Ubuntu' or ansible_distribution_version is version('20.04', '<') - name: "Docker | Ensure additional dependencies are installed (on Ubuntu >= 20.04)." apt: name: gnupg state: present + update_cache: true when: ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '>=') - name: "Docker | Add Docker apt key." diff --git a/roles/marzban/tasks/post-deploy.yml b/roles/marzban/tasks/post-deploy.yml index 44a7952..8f6692e 100644 --- a/roles/marzban/tasks/post-deploy.yml +++ b/roles/marzban/tasks/post-deploy.yml @@ -8,8 +8,8 @@ group: root mode: '0644' loop: - - { name: 'marzban_mysql_user_password', path: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/pass_marzban_mysql_user_password" } - - { name: 'marzban_mysql_root_password', path: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/pass_marzban_mysql_root_password" } + - { name: 'marzban_mysql_user_password', path: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/vault_marzban_mysql_user_password" } + - { name: 'marzban_mysql_root_password', path: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/vault_marzban_mysql_root_password" } when: marzban_mysql_instance is defined and marzban_mysql_instance - name: "Marzban | Post-deploy | Install marzban-cli" diff --git a/roles/marzban/tasks/prepare.yml b/roles/marzban/tasks/prepare.yml index 925fabe..4eb0db2 100644 --- a/roles/marzban/tasks/prepare.yml +++ b/roles/marzban/tasks/prepare.yml @@ -7,10 +7,43 @@ - name: "Marzban | Prepare | Mysql" block: + - name: "Marzban | Prepare | Mysql | Check if marzban_mysql_user_password file exists" + stat: + path: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/vault_marzban_mysql_user_password" + register: mysql_user_password_file + + - name: "Marzban | Prepare | Mysql | Check if marzban_mysql_root_password file exists" + stat: + path: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/vault_marzban_mysql_root_password" + register: mysql_root_password_file + + - name: "Marzban | Prepare | Mysql | Read marzban_mysql_user_password from file" + slurp: + src: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/vault_marzban_mysql_user_password" + register: mysql_user_password_content + when: mysql_user_password_file.stat.exists + + - name: "Marzban | Prepare | Mysql | Read marzban_mysql_root_password from file" + slurp: + src: "{{ marzban_system_dirs | json_query('[*].vault_dir') | first }}/vault_marzban_mysql_root_password" + register: mysql_root_password_content + when: mysql_root_password_file.stat.exists + + - name: "Marzban | Prepare | Mysql | Set marzban_mysql_user_password from file if exists" + set_fact: + marzban_mysql_user_password: "{{ mysql_user_password_content.content | b64decode }}" + when: mysql_user_password_file.stat.exists + + - name: "Marzban | Prepare | Mysql | Set marzban_mysql_root_password from file if exists" + set_fact: + marzban_mysql_root_password: "{{ mysql_root_password_content.content | b64decode }}" + when: mysql_root_password_file.stat.exists + - name: "Marzban | Prepare | Mysql | Set marzban_mysql_user_password if not defined or empty" set_fact: marzban_mysql_user_password: "{{ lookup('password', '/dev/null length=20') }}" when: + - not mysql_user_password_file.stat.exists - marzban_mysql_user_password is not defined or marzban_mysql_user_password == '' - inventory_hostname == groups[marzban_main_group_name][0] | default(omit) @@ -18,6 +51,7 @@ set_fact: marzban_mysql_root_password: "{{ lookup('password', '/dev/null length=20') }}" when: + - not mysql_root_password_file.stat.exists - marzban_mysql_root_password is not defined or marzban_mysql_root_password == '' - inventory_hostname == groups[marzban_main_group_name][0] | default(omit) diff --git a/roles/marzban/tasks/warp.yml b/roles/marzban/tasks/warp.yml index a11a627..9f2d47e 100644 --- a/roles/marzban/tasks/warp.yml +++ b/roles/marzban/tasks/warp.yml @@ -8,18 +8,21 @@ - apt-transport-https - ca-certificates state: present + update_cache: true when: marzban_warp_add_repo | bool - name: "Marzban | Warp | Ensure additional dependencies are installed (on Ubuntu < 20.04 and any other systems)." apt: name: gnupg2 state: present + update_cache: true when: ansible_distribution != 'Ubuntu' or ansible_distribution_version is version('20.04', '<') - name: "Marzban | Warp | Ensure additional dependencies are installed (on Ubuntu >= 20.04)." apt: name: gnupg state: present + update_cache: true when: ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '>=') - name: "Marzban | Warp | Add cloudflare-warp apt key."