diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml
index 9837b11..4d8aeef 100644
--- a/.github/workflows/linter.yml
+++ b/.github/workflows/linter.yml
@@ -17,12 +17,12 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Check out the codebase.
- uses: actions/checkout@v2
+ uses: actions/checkout@v4
with:
path: 'v-kamerdinerov.marzban-haproxy-ansible'
- name: Set up Python 3.
- uses: actions/setup-python@v2
+ uses: actions/setup-python@v5
with:
python-version: '3.x'
diff --git a/group_vars/marzban/marzban.yml b/group_vars/marzban/marzban.yml
index b24478b..b2e0e63 100644
--- a/group_vars/marzban/marzban.yml
+++ b/group_vars/marzban/marzban.yml
@@ -7,7 +7,7 @@ marzban_domain: example-domain.com
marzban_panel_uri: "panel.{{ marzban_domain }}"
# SNI for traffic masking
-marzban_sni: "discord.com"
+marzban_sni: "awesome.sni"
# Login credentials for panel access
marzban_panel_login: "admin"
diff --git a/roles/common/tasks/cert.yml b/roles/common/tasks/cert.yml
index c0e5908..8b3b782 100644
--- a/roles/common/tasks/cert.yml
+++ b/roles/common/tasks/cert.yml
@@ -12,3 +12,6 @@
when: item.key.endswith('.cert')
register: _ca_certificates_copied
notify: Update ca-certificates
+
+- name: Flush handlers
+ meta: flush_handlers
diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml
index 5d29c59..de65754 100644
--- a/roles/common/tasks/main.yml
+++ b/roles/common/tasks/main.yml
@@ -1,10 +1,10 @@
---
+- name: SSH
+ include_tasks: ssh_port.yml
+ tags: ssh
- name: Common
include_tasks: common.yml
tags: common
-# loop: "{{ groups['marzban'] }}"
-# loop_control:
-# loop_var: host
- name: Limits
include_tasks: limits.yml
tags: limits
@@ -14,9 +14,6 @@
- name: Certificate
include_tasks: cert.yml
tags: certificate
-- name: SSH
- include_tasks: ssh_port.yml
- tags: ssh
- name: Kernel
include_tasks: kernel.yml
tags: kernel
diff --git a/roles/common/tasks/ssh_port.yml b/roles/common/tasks/ssh_port.yml
index 812b0a5..6aaa8fc 100644
--- a/roles/common/tasks/ssh_port.yml
+++ b/roles/common/tasks/ssh_port.yml
@@ -105,6 +105,13 @@
- 'ansible_distribution'
- 'ansible_distribution_major_version'
+ - name: "Common | SSH | Ensure ssh enabled and started"
+ become: true
+ service:
+ name: ssh
+ state: started
+ enabled: true
+
# We notified "Restart sshd" if we modified the sshd config.
# By calling flush_handlers, we make sure the handler is run *right now*
- name: "Common | SSH | Ensure SSH is reloaded if need be"
diff --git a/roles/marzban/defaults/main.yml b/roles/marzban/defaults/main.yml
index d7b0eca..523c24d 100644
--- a/roles/marzban/defaults/main.yml
+++ b/roles/marzban/defaults/main.yml
@@ -5,6 +5,7 @@ marzban_system_dirs:
- vault_dir: "/opt/marzban/credentials"
- work_dir: "/var/lib/marzban"
- certs_dir: "/var/lib/marzban/certs"
+ - templates_dir: "/var/lib/marzban/templates"
marzban_node_dirs:
- base_dir: "/opt/marzban"
@@ -13,8 +14,10 @@ marzban_node_dirs:
marzban_ssl_certfile: "{{ vault_ssl_certs.keys() | select('search', 'cert') | list | first }}"
marzban_ssl_keyfile: "{{ vault_ssl_certs.keys() | select('search', 'key') | list | first }}"
+marzban_image: "gozargah/marzban"
marzban_image_tag: "latest"
+marzban_haproxy_image: "haproxy"
marzban_haproxy_image_tag: "2.4.25"
marzban_haproxy_dirs:
- etc_dir: "/etc/haproxy"
@@ -82,6 +85,7 @@ marzban_docs: false
### Mysql(mariadb) configuration
marzban_mysql_instance: false
+marzban_mysql_image: "mariadb"
marzban_mysql_image_tag: "lts"
marzban_mysql_db_name: "marzban"
marzban_mysql_user_name: "marzban"
@@ -104,3 +108,6 @@ marzban_backup_cron: { minute: "0", hour: "2", day: "*", month: "*", weekday: "*
marzban_ssl_node_path: "/var/lib/marzban-node/ssl_client_cert.pem"
marzban_ssl_node_certificate: ""
marzban_nodes_host_info: ""
+
+marzban_node_image: "gozargah/marzban-node"
+marzban_node_image_tag: "latest"
diff --git a/roles/marzban/files/index.html b/roles/marzban/files/index.html
new file mode 100644
index 0000000..6fa394a
--- /dev/null
+++ b/roles/marzban/files/index.html
@@ -0,0 +1,535 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Подписка
+
+
+ Имя: {{ user.username }}
+
+
+ Статус{% if user.status.value =='active' %}
Активна{% elif user.status.value == 'limited' %}
Ограничена{% elif user.status.value == 'expired' %}
Истекла{% else %}
Заблокирована{% endif %}
+
+
+ Трафик{{ user.used_traffic | bytesformat }} / {% if not user.data_limit %}∞{% else %}{{ user.data_limit | bytesformat }}{% endif %}
+
+
+ Истекает
+
+
+ Скопировать подписку
+ Скопировано!
+
+
+ Скопировать конфиг
+ Скопировано!
+
+
+
+
+
+
+
+
+
Приложения
+
+
+
+
+
+
Streisand
+ Streisand - рекомендуемое приложение для IOS 14+
+
+
+
+
Инструкция по подключению
+
1. Нажмите Скачать в AppStore, чтобы установить приложение
+
2. Нажмите Добавить подписку
+
3. Перейдите Настройки -> Подписка и поставьте чекбокс Обновить при открытии.
+ confirm
+
4. Нажмите Добавить роутинг, в приложении нажмите Роутинг и поставьте рядом с ним галочку, нажмите сверху на чекбокс, чтобы применить правила роутинга. Роутинг - правила для перенаправления трафика, без него приложение может работать неправильно. confirm
+
5. Осталось выбрать конфигурацию подключения и нажать Подключиться. Готово! confirm
+
+
+
+
+
+
+ Android
+
+
+
+
v2rayNG
+ v2rayNG - рекомендуемое приложение для Android
+
+
+
+
+
Инструкция по подключению
+
1. Нажмите Скачать в Google Play, чтобы установить приложение.
+
2. Выберите 3 вертикальные полоски.
+
3. Выберите Группы. Добавить новую группу.
+
4. Выберите тип группы - подписка, вставьте URL.
+
4. Теперь осталось выбрать конфигурацию и подключиться, нажав на иконку приложения в правом нижнем углу. Готово! confirm
+
+
+
+
+
+
+
+
+
Hiddify-Next
+ Hiddify-Next - рекомендуемое приложение для Windows
+
+
+
+
+
Инструкция по подключению
+
1. Нажмите Скачать с GitHub, чтобы установить приложение
+
2. Смените язык на Русский, в качестве региона укажите Россия (это необходимо, чтобы настройки роутинга применились автоматически) и нажмите Начать confirm
+
3. Нажмите Добавить подписку
+
4. Нажмите подключиться. Готово! confirm
+
+
+
+
+
+
+
+
+
Hiddify-Next
+ Hiddify-Next - рекомендуемое приложение для macOS
+
+
+
+
+
Инструкция по подключению
+
1. Нажмите Скачать с GitHub, чтобы установить приложение
+
2. Смените язык на Русский, в качестве региона укажите Россия (это необходимо, чтобы настройки роутинга применились автоматически) и нажмите Начать confirm
+
3. Нажмите Добавить подписку
+
4. Нажмите подключиться. Готово! confirm
+
+
+
+
+
+
+
+
+
Hiddify-Next
+ Hiddify-Next - рекомендуемое приложение для Linux
+
+
+
+
+
Инструкция по подключению
+
1. Нажмите Скачать с GitHub, чтобы установить приложение
+
2. Смените язык на Русский, в качестве региона укажите Россия (это необходимо, чтобы настройки роутинга применились автоматически) и нажмите Начать confirm
+
3. Нажмите Добавить подписку
+
4. Нажмите подключиться. Готово! confirm
+
+
+
+
+
+
+
+
+
Помощь
+
+
+
+
+
+
+ Роутинг - правила для перенаправления трафика, они предоставляют гибкую настроку для подключения.
+
+
+
+
+
+
+
+
+ Подписка - ссылка в специальном формате, по которой приложение загружает с сервера данные, необходимые для подключения.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/roles/marzban/files/marzban_backup.sh b/roles/marzban/files/marzban_backup.sh
index ba1ba41..a6d98eb 100644
--- a/roles/marzban/files/marzban_backup.sh
+++ b/roles/marzban/files/marzban_backup.sh
@@ -25,114 +25,114 @@ HOSTNAME_NODE=$(hostname)
# Logging function with levels and colors
log() {
- LEVEL="$1"
- MSG="$2"
- TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
- case "${LEVEL}" in
- INFO)
- printf "[${TIMESTAMP}] [${FontColor_Green}${LEVEL}${FontColor_Suffix}] %s\n" "${MSG}" | tee -a "$LOG_FILE"
- ;;
- WARN)
- printf "[${TIMESTAMP}] [${FontColor_Yellow}${LEVEL}${FontColor_Suffix}] %s\n" "${MSG}" | tee -a "$LOG_FILE"
- ;;
- ERROR)
- printf "[${TIMESTAMP}] [${FontColor_Red}${LEVEL}${FontColor_Suffix}] %s\n" "${MSG}" | tee -a "$LOG_FILE" >&2
- ;;
- *)
- printf "[${TIMESTAMP}] %s\n" "${MSG}" | tee -a "$LOG_FILE"
- ;;
- esac
+ LEVEL="$1"
+ MSG="$2"
+ TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
+ case "${LEVEL}" in
+ INFO)
+ printf "[${TIMESTAMP}] [${FontColor_Green}${LEVEL}${FontColor_Suffix}] %s\n" "${MSG}" | tee -a "$LOG_FILE"
+ ;;
+ WARN)
+ printf "[${TIMESTAMP}] [${FontColor_Yellow}${LEVEL}${FontColor_Suffix}] %s\n" "${MSG}" | tee -a "$LOG_FILE"
+ ;;
+ ERROR)
+ printf "[${TIMESTAMP}] [${FontColor_Red}${LEVEL}${FontColor_Suffix}] %s\n" "${MSG}" | tee -a "$LOG_FILE" >&2
+ ;;
+ *)
+ printf "[${TIMESTAMP}] %s\n" "${MSG}" | tee -a "$LOG_FILE"
+ ;;
+ esac
}
# Function to create backup directory
create_backup_dir() {
- if [ ! -d "$BACKUP_DIR" ]; then
- log INFO "Creating backup directory: $BACKUP_DIR"
- mkdir -p "$BACKUP_DIR"
- fi
+ if [ ! -d "$BACKUP_DIR" ]; then
+ log INFO "Creating backup directory: $BACKUP_DIR"
+ mkdir -p "$BACKUP_DIR"
+ fi
}
# Function to backup directories
backup_directories() {
- create_backup_dir
- BACKUP_PATH="$BACKUP_DIR/backup_$CURRENT_DATE"
- log INFO "Backing up directories to $BACKUP_PATH"
+ create_backup_dir
+ BACKUP_PATH="$BACKUP_DIR/backup_$CURRENT_DATE"
+ log INFO "Backing up directories to $BACKUP_PATH"
- # Create directory structure for backup
- mkdir -p "$BACKUP_PATH/lib"
- mkdir -p "$BACKUP_PATH/opt"
+ # Create directory structure for backup
+ mkdir -p "$BACKUP_PATH/lib"
+ mkdir -p "$BACKUP_PATH/opt"
- # Backup contents
- cp -r $LIB_SRC_DIR "$BACKUP_PATH/lib/" || log WARN "Failed to backup lib directory."
- cp -r $OPT_SRC_DIR "$BACKUP_PATH/opt/" || log WARN "Failed to backup opt directory."
+ # Backup contents
+ cp -r $LIB_SRC_DIR "$BACKUP_PATH/lib/" || log WARN "Failed to backup lib directory."
+ cp -r $OPT_SRC_DIR "$BACKUP_PATH/opt/" || log WARN "Failed to backup opt directory."
- log INFO "Directories backed up successfully."
+ log INFO "Directories backed up successfully."
}
# Function to backup MySQL databases
backup_databases() {
- if grep -q "SQLALCHEMY_DATABASE_URL" "$ENV_FILE" && ! grep -q "sqlite" "$ENV_FILE"; then
- # Fixed user root
- DB_USER="root"
-
- # Extract root password from environment file
- DB_PASSWORD=$(grep -oP '(?<=ROOT_PASSWORD=).*' "$ENV_FILE")
-
- # Install mysqldump if not installed
- if ! command -v mysqldump &> /dev/null; then
- log WARN "mysqldump not found, installing..."
- apt-get update && apt-get install -y mysql-client || log ERROR "Failed to install mysql-client."
- fi
-
- # Dump databases
- DB_BACKUP_PATH="$BACKUP_PATH/db-backup"
- mkdir -p "$DB_BACKUP_PATH"
-
- # Get the list of databases and exclude system databases
- databases=$(mysql -h 127.0.0.1 --user="$DB_USER" --password="$DB_PASSWORD" -e "SHOW DATABASES;" | tr -d "| " | grep -v -E 'Database|information_schema|mysql|performance_schema|sys')
-
- for db in $databases; do
- log INFO "Dumping database: $db"
- # Use additional parameters to avoid errors
- mysqldump -h 127.0.0.1 --force --opt --user="$DB_USER" --password="$DB_PASSWORD" --single-transaction --skip-lock-tables --no-tablespaces --databases "$db" > "$DB_BACKUP_PATH/$db.sql" || log ERROR "Getting some error while dump database: $db"
- done
- log INFO "Databases dumped successfully."
- else
- log INFO "SQLite detected or SQLALCHEMY_DATABASE_URL not found. No MySQL databases to backup."
- fi
+ if grep -q "SQLALCHEMY_DATABASE_URL" "$ENV_FILE" && ! grep -q "sqlite" "$ENV_FILE"; then
+ # Fixed user root
+ DB_USER="root"
+
+ # Extract root password from environment file
+ DB_PASSWORD=$(grep -oP '(?<=ROOT_PASSWORD=).*' "$ENV_FILE")
+
+ # Install mysqldump if not installed
+ if ! command -v mysqldump &>/dev/null; then
+ log WARN "mysqldump not found, installing..."
+ apt-get update && apt-get install -y mysql-client || log ERROR "Failed to install mysql-client."
+ fi
+
+ # Dump databases
+ DB_BACKUP_PATH="$BACKUP_PATH/db-backup"
+ mkdir -p "$DB_BACKUP_PATH"
+
+ # Get the list of databases and exclude system databases
+ databases=$(mysql -h 127.0.0.1 --user="$DB_USER" --password="$DB_PASSWORD" -e "SHOW DATABASES;" | tr -d "| " | grep -v -E 'Database|information_schema|mysql|performance_schema|sys')
+
+ for db in $databases; do
+ log INFO "Dumping database: $db"
+ # Use additional parameters to avoid errors
+ mysqldump -h 127.0.0.1 --force --opt --user="$DB_USER" --password="$DB_PASSWORD" --single-transaction --skip-lock-tables --no-tablespaces --databases "$db" >"$DB_BACKUP_PATH/$db.sql" || log ERROR "Getting some error while dump database: $db"
+ done
+ log INFO "Databases dumped successfully."
+ else
+ log INFO "SQLite detected or SQLALCHEMY_DATABASE_URL not found. No MySQL databases to backup."
+ fi
}
# Function to send backup to Telegram
send_to_telegram() {
- # Extract Telegram bot token and chat ID from environment file
- TELEGRAM_BOT_TOKEN=$(grep -oP '(?<=TELEGRAM_BOT_TOKEN=).*' "$ENV_FILE")
- TELEGRAM_CHAT_ID=$(grep -oP '(?<=TELEGRAM_CHAT_ID=).*' "$ENV_FILE")
-
- if [ -n "$TELEGRAM_BOT_TOKEN" ] && [ -n "$TELEGRAM_CHAT_ID" ]; then
- TAR_FILE="$BACKUP_DIR/backup_$CURRENT_DATE.tar.gz"
- log INFO "Creating tarball $TAR_FILE"
- tar -czf "$TAR_FILE" -C "$BACKUP_DIR" "backup_$CURRENT_DATE" || log ERROR "Failed to create tarball."
-
- log INFO "Sending backup to Telegram chat ID $TELEGRAM_CHAT_ID"
- curl -F chat_id="${TELEGRAM_CHAT_ID}" \
- -F caption="Backup from $HOSTNAME_NODE at $CURRENT_DATE" \
- -F parse_mode="HTML" \
- -F document=@"$TAR_FILE" \
- https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument || log ERROR "Failed to send backup to Telegram."
-
- log INFO "Backup sent to Telegram successfully."
- else
- log WARN "Telegram BOT token or chat ID not provided. Skipping upload."
- fi
+ # Extract Telegram bot token and chat ID from environment file
+ TELEGRAM_BOT_TOKEN=$(grep -oP '(?<=TELEGRAM_BOT_TOKEN=).*' "$ENV_FILE")
+ TELEGRAM_CHAT_ID=$(grep -oP '(?<=TELEGRAM_CHAT_ID=).*' "$ENV_FILE")
+
+ if [ -n "$TELEGRAM_BOT_TOKEN" ] && [ -n "$TELEGRAM_CHAT_ID" ]; then
+ TAR_FILE="$BACKUP_DIR/backup_$CURRENT_DATE.tar.gz"
+ log INFO "Creating tarball $TAR_FILE"
+ tar -czf "$TAR_FILE" -C "$BACKUP_DIR" "backup_$CURRENT_DATE" || log ERROR "Failed to create tarball."
+
+ log INFO "Sending backup to Telegram chat ID $TELEGRAM_CHAT_ID"
+ curl -F chat_id="${TELEGRAM_CHAT_ID}" \
+ -F caption="Backup from $HOSTNAME_NODE at $CURRENT_DATE" \
+ -F parse_mode="HTML" \
+ -F document=@"$TAR_FILE" \
+ https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument || log ERROR "Failed to send backup to Telegram."
+
+ log INFO "Backup sent to Telegram successfully."
+ else
+ log WARN "Telegram BOT token or chat ID not provided. Skipping upload."
+ fi
}
# Main backup process
main() {
- log INFO "Starting backup process."
- backup_directories
- backup_databases
- send_to_telegram
- log INFO "Backup process completed."
+ log INFO "Starting backup process."
+ backup_directories
+ backup_databases
+ send_to_telegram
+ log INFO "Backup process completed."
}
# Run the main process
diff --git a/roles/marzban/tasks/backup.yml b/roles/marzban/tasks/backup.yml
index d31cf10..c1c38cc 100644
--- a/roles/marzban/tasks/backup.yml
+++ b/roles/marzban/tasks/backup.yml
@@ -1,5 +1,13 @@
---
+- name: "Marzban | Backup | Prepare | Install cli utility"
+ apt:
+ name:
+ - mysql-client
+ state: present
+ update_cache: true
+ when: marzban_mysql_instance is defined and marzban_mysql_instance
+
- name: "Marzban | Backup | Add backup script"
copy:
src: "marzban_backup.sh"
diff --git a/roles/marzban/tasks/conf/panel.yml b/roles/marzban/tasks/conf/panel.yml
index a6253d5..0761c24 100644
--- a/roles/marzban/tasks/conf/panel.yml
+++ b/roles/marzban/tasks/conf/panel.yml
@@ -29,12 +29,18 @@
- name: "Marzban | Configure {{ role | upper() }} | Info"
debug:
- msg: "Get gozargah/marzban docker image..."
+ msg: |
+ INFO:
+ --------------------------------------------
+ Get marzban docker image...
+ Image name: {{ marzban_image }}
+ Image tag: {{ marzban_image_tag }}
+ --------------------------------------------
changed_when: false
when: not key_stat.stat.exists
- name: "Marzban | Configure {{ role | upper() }} | Generate X25519 key if it does not exist"
- command: "docker run --rm gozargah/marzban xray x25519"
+ command: "docker run --rm {{ marzban_image }} xray x25519"
register: generate_key_result
changed_when: false
when: not key_stat.stat.exists
@@ -75,9 +81,16 @@
src: "{{ item.src }}"
dest: "{{ marzban_system_dirs | json_query('[*].work_dir') | first }}/{{ item.dst }}"
mode: "{{ item.mode }}"
+ validate: /usr/bin/jq empty %s
loop:
- {src: xray_config.json.j2, dst: xray_config.json, mode: "0644"}
+- name: "Marzban | Configure {{ role | upper() }} | Add subscription template"
+ copy:
+ src: "index.html"
+ dest: "{{ marzban_system_dirs | json_query('[*].templates_dir') | first }}/index.html"
+ mode: "0644"
+
- name: "Marzban | Configure {{ role | upper() }} | Template ssl certificate"
copy:
dest: "{{ (marzban_system_dirs | json_query('[*].certs_dir') | first) }}/{{ item.key }}"
@@ -88,7 +101,6 @@
content: "{{ item.value }}"
loop: "{{ vault_ssl_certs | dict2items }}"
-
- name: "Marzban | Configure {{ role | upper() }} | Create and start services"
community.docker.docker_compose_v2:
project_src: "{{ marzban_system_dirs | json_query('[*].base_dir') | first }}"
@@ -106,7 +118,7 @@
accept: "application/json"
Content-Type: "application/x-www-form-urlencoded"
body:
- grant_type: ""
+ grant_type: "password"
username: "{{ marzban_panel_login }}"
password: "{{ marzban_panel_password }}"
scope: ""
diff --git a/roles/marzban/tasks/warp.yml b/roles/marzban/tasks/warp.yml
index 9f2d47e..6b2f295 100644
--- a/roles/marzban/tasks/warp.yml
+++ b/roles/marzban/tasks/warp.yml
@@ -2,57 +2,71 @@
- name: "Marzban | Warp | Gather instance facts"
setup: {}
-- name: "Marzban | Warp | Ensure dependencies are installed."
- apt:
- name:
- - 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."
- ansible.builtin.get_url:
- url: "{{ marzban_warp_apt_gpg_key }}"
- dest: "{{ marzban_warp_apt_gpg_key_path }}"
- mode: '0644'
- force: false
- checksum: "{{ marzban_warp_apt_gpg_key_checksum | default(omit) }}"
- ignore_errors: "{{ marzban_warp_apt_ignore_key_error }}"
- when: marzban_warp_add_repo | bool
-
-
-- name: "Marzban | Warp | Add cloudflare-warp repository."
- apt_repository:
- repo: "{{ marzban_warp_apt_repository }}"
- state: present
- filename: "{{ marzban_warp_apt_filename }}"
- update_cache: true
- when: marzban_warp_add_repo | bool
-
-- name: "Marzban | Warp | Install cloudflare-warp packages."
- package:
- name: "{{ marzban_warp_packages }}"
- state: "{{ marzban_warp_packages_state }}"
- ignore_errors: "{{ ansible_check_mode }}"
+- name: "Marzban | Warp | Apt install"
+ block:
+ - name: "Marzban | Warp | Ensure dependencies are installed."
+ apt:
+ name:
+ - 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."
+ ansible.builtin.get_url:
+ url: "{{ marzban_warp_apt_gpg_key }}"
+ dest: "{{ marzban_warp_apt_gpg_key_path }}"
+ mode: '0644'
+ force: false
+ checksum: "{{ marzban_warp_apt_gpg_key_checksum | default(omit) }}"
+ ignore_errors: "{{ marzban_warp_apt_ignore_key_error }}"
+ when: marzban_warp_add_repo | bool
+
+
+ - name: "Marzban | Warp | Add cloudflare-warp repository."
+ apt_repository:
+ repo: "{{ marzban_warp_apt_repository }}"
+ state: present
+ filename: "{{ marzban_warp_apt_filename }}"
+ update_cache: true
+ when: marzban_warp_add_repo | bool
+
+ - name: "Marzban | Warp | Install cloudflare-warp packages."
+ package:
+ name: "{{ marzban_warp_packages }}"
+ state: "{{ marzban_warp_packages_state }}"
+ ignore_errors: "{{ ansible_check_mode }}"
+ when: marzban_warp_apt_install is defined and marzban_warp_apt_install
+
+- name: "Marzban | Warp | Deb install"
+ block:
+ - name: "Marzban | Warp | Install cloudflare-warp packages via deb pkg"
+ apt:
+ deb: "{{ marzban_warp_deb_package }}"
+ - name: "Marzban | Warp | Hold cloudflare-warp pkg"
+ dpkg_selections:
+ name: "{{ marzban_warp_package_name }}"
+ selection: hold
+ when: marzban_warp_deb_package is defined and marzban_warp_deb_package
- name: "Marzban | Warp | Check warp client"
- command: warp-cli --accept-tos account
+ command: warp-cli --accept-tos status
register: warp_registration_status
changed_when: warp_registration_status.rc == 0
@@ -62,7 +76,7 @@
- name: "Marzban | Warp | Check for missing registration"
set_fact:
- warp_missing_registration: "{{ 'Missing registration' in warp_registration_status.stdout }}"
+ warp_missing_registration: "{{ 'Missing' in warp_registration_status.stdout }}"
- name: "Marzban | Warp"
block:
@@ -71,12 +85,12 @@
msg: "Cloudflare WARP Account Registration in progress..."
- name: "Marzban | Warp | Init warp client"
- command: warp-cli --accept-tos register
+ command: warp-cli --accept-tos registration new
register: warp_registration
changed_when: warp_registration.rc == 0
- name: "Marzban | Warp | Set warp mode proxy"
- command: warp-cli --accept-tos set-mode proxy
+ command: warp-cli --accept-tos mode proxy
register: warp_mode_proxy
changed_when: warp_mode_proxy.rc == 0
diff --git a/roles/marzban/templates/docker-compose-node.yml.j2 b/roles/marzban/templates/docker-compose-node.yml.j2
index bfc73c1..0680aeb 100644
--- a/roles/marzban/templates/docker-compose-node.yml.j2
+++ b/roles/marzban/templates/docker-compose-node.yml.j2
@@ -1,6 +1,6 @@
services:
haproxy:
- image: haproxy:{{ marzban_haproxy_image_tag }}
+ image: {{ marzban_haproxy_image }}:{{ marzban_haproxy_image_tag }}
restart: always
network_mode: host
user: root
@@ -12,7 +12,7 @@ services:
- marzban-node
marzban-node:
- image: gozargah/marzban-node:latest
+ image: {{ marzban_node_image }}:{{ marzban_node_image_tag }}
restart: always
env_file: .env
network_mode: host
diff --git a/roles/marzban/templates/docker-compose.yml.j2 b/roles/marzban/templates/docker-compose.yml.j2
index a42a04c..31bd263 100644
--- a/roles/marzban/templates/docker-compose.yml.j2
+++ b/roles/marzban/templates/docker-compose.yml.j2
@@ -2,7 +2,7 @@ version: '3.8'
services:
haproxy:
- image: haproxy:{{ marzban_haproxy_image_tag }}
+ image: {{ marzban_haproxy_image }}:{{ marzban_haproxy_image_tag }}
restart: always
network_mode: host
user: root
@@ -14,7 +14,7 @@ services:
- marzban
marzban:
- image: gozargah/marzban:{{ marzban_image_tag }}
+ image: {{ marzban_image }}:{{ marzban_image_tag }}
restart: always
env_file: .env
network_mode: host
@@ -27,7 +27,7 @@ services:
condition: service_healthy
mariadb:
- image: mariadb:{{ marzban_mysql_image_tag }}
+ image: {{ marzban_mysql_image }}:{{ marzban_mysql_image_tag }}
restart: always
env_file: .env
network_mode: host
diff --git a/roles/marzban/templates/env.j2 b/roles/marzban/templates/env.j2
index 75cabd4..5e5e5f5 100644
--- a/roles/marzban/templates/env.j2
+++ b/roles/marzban/templates/env.j2
@@ -12,6 +12,8 @@ UVICORN_PORT = {{ marzban_panel_port }}
UVICORN_SSL_CERTFILE = "/var/lib/marzban/certs/{{ marzban_ssl_certfile }}"
UVICORN_SSL_KEYFILE = "/var/lib/marzban/certs/{{ marzban_ssl_keyfile }}"
XRAY_SUBSCRIPTION_URL_PREFIX = https://{{ marzban_panel_uri }}
+CUSTOM_TEMPLATES_DIRECTORY="{{ marzban_system_dirs | json_query('[*].templates_dir') | first }}/"
+SUBSCRIPTION_PAGE_TEMPLATE="index.html"
XRAY_JSON = "{{ marzban_system_dirs | json_query('[*].work_dir') | first }}/xray_config.json"
SUDO_USERNAME="{{ marzban_panel_login }}"
SUDO_PASSWORD="{{ marzban_panel_password }}"
diff --git a/roles/marzban/vars/main.yml b/roles/marzban/vars/main.yml
index 7ee6b03..1de10ed 100644
--- a/roles/marzban/vars/main.yml
+++ b/roles/marzban/vars/main.yml
@@ -6,6 +6,8 @@ marzban_warp_add_repo: true
# marzban_warp repo URL.
marzban_warp_repo_url: https://pkg.cloudflareclient.com
+
+marzban_warp_apt_install: false
marzban_warp_apt_release_channel: main
marzban_warp_apt_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
marzban_warp_apt_repository: "deb [arch={{ marzban_warp_apt_arch }} signed-by={{ marzban_warp_apt_gpg_key_path }}] {{ marzban_warp_repo_url }} {{ ansible_distribution_release }} {{ marzban_warp_apt_release_channel }}"
@@ -14,11 +16,16 @@ marzban_warp_apt_gpg_key: "{{ marzban_warp_repo_url }}/pubkey.gpg"
marzban_warp_apt_gpg_key_checksum: "sha256:1d78962d81c4c1061ef6b80bb28e85d6a76735d73677cf46f54ff5ea78abc94e"
marzban_warp_apt_gpg_key_path: "/usr/share/keyrings/cloudflare-warp-archive-keyring.asc"
marzban_warp_apt_filename: "cloudflare-client"
+marzban_warp_packages_state: present
+marzban_warp_package_name: "cloudflare-warp"
marzban_warp_packages:
- - "cloudflare-warp"
+ - "{{ marzban_warp_package_name }}={{ marzban_warp_pkg_version }}"
+marzban_warp_pkg_version: "2024.6.497-1"
+
+marzban_warp_deb_install: true
+marzban_warp_deb_package: "{{ marzban_warp_repo_url }}/pool/{{ ansible_distribution_release }}/{{ marzban_warp_apt_release_channel }}/c/cloudflare-warp/cloudflare-warp_{{ marzban_warp_pkg_version }}_amd64.deb"
-marzban_warp_packages_state: present
marzban_cli_script_url: "https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh"
marzban_cli_install_path: "/usr/local/bin/marzban"