diff --git a/defaults/main.yaml b/defaults/main.yaml index 4ba5873..531065a 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -5,7 +5,7 @@ wireguard_ui_network_mode: "host" wireguard_ui_config_dir: "/opt/{{ wireguard_ui_container_name }}" wireguard_ui_container_registry: "{{ container_registry | default(docker_registry) | default('docker.io') }}" wireguard_ui_image_name: "ngoduykhanh/wireguard-ui" -wireguard_ui_image_tag: "0.3.7" +wireguard_ui_image_tag: "0.4.0" wireguard_ui_systemd_unit_name: "{{ wireguard_ui_container_name }}.service" wireguard_ui_watcher_systemd_service_unit_name: "{{ wireguard_ui_container_name }}-watcher.service" wireguard_ui_watcher_systemd_path_unit_name: "{{ wireguard_ui_container_name }}-watcher.path" @@ -17,13 +17,14 @@ wireguard_ui_default_volumes: #wireguard_ui_env: {} wireguard_ui_default_env: - WGUI_USERNAME: admin - WGUI_PASSWORD: admin - WGUI_MTU: 1420 - BIND_ADDRESS: 127.0.0.1:5001 - SESSION_SECRET: 74f8155b3c91437db6e6c29c28e23ecc - WGUI_CONFIG_FILE_PATH: /etc/wireguard/wg0.conf - BASE_PATH: / + WGUI_USERNAME: "admin" + WGUI_PASSWORD: "admin" + WGUI_MTU: "1420" + WGUI_SERVER_INTERFACE_ADDRESSES: "10.252.1.1/24" + BIND_ADDRESS: "127.0.0.1:5001" + SESSION_SECRET: "74f8155b3c91437db6e6c29c28e23ecc" + WGUI_CONFIG_FILE_PATH: "/etc/wireguard/wg0.conf" + BASE_PATH: "/" # Example for auth #wireguard_ui_container_registry_auth: diff --git a/handlers/main.yaml b/handlers/main.yaml index 9c34d78..2cad888 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -8,7 +8,7 @@ detach: true restart_policy: unless-stopped env: "{{ wireguard_ui_combined_env }}" - volumes: "{{ wireguard_ui_combined_volumes }}" + volumes: "{{ wireguard_ui_volumes }}" when: - wireguard_ui_container_engine == 'docker' - not wireguard_ui_container.changed @@ -23,7 +23,7 @@ state: started restart: yes env: "{{ wireguard_ui_combined_env }}" - volumes: "{{ wireguard_ui_combined_volumes }}" + volumes: "{{ wireguard_ui_volumes }}" when: - wireguard_ui_container_engine == 'podman' - not wireguard_ui_container.changed diff --git a/tasks/RedHat/podman.yaml b/tasks/RedHat/podman.yaml index 63758cc..714c65d 100644 --- a/tasks/RedHat/podman.yaml +++ b/tasks/RedHat/podman.yaml @@ -11,10 +11,20 @@ loop: '{{ wireguard_ui_container_registry_auth | dict2items }}' when: wireguard_ui_container_registry_auth is defined - - name: Create configuration dir for WireGuard UI + - name: Create configuration dir and subdirs for WireGuard UI file: - name: "{{ wireguard_ui_config_dir }}" + name: "{{ item }}" state: directory + loop: + - "{{ wireguard_ui_config_dir }}" + - "{{ wireguard_ui_config_dir }}/server" + + - name: Force login and password change + template: + dest: "{{ wireguard_ui_config_dir }}/server/users.json" + src: users.json.j2 + register: wireguard_ui_auth + notify: Restart WireGuard UI with podman - name: Create WireGuard UI with podman containers.podman.podman_container: @@ -23,18 +33,13 @@ network_mode: "{{ wireguard_ui_network_mode }}" image: "{{ wireguard_ui_container_registry }}/{{ wireguard_ui_image_name }}:{{ wireguard_ui_image_tag }}" state: created + cap_add: + - NET_ADMIN env: "{{ wireguard_ui_combined_env }}" - volumes: "{{ wireguard_ui_combined_volumes }}" + volumes: "{{ wireguard_ui_volumes }}" register: wireguard_ui_container notify: Restart WireGuard UI with podman - - name: Force login and password change - template: - dest: "{{ wireguard_ui_config_dir }}/server/users.json" - src: users.json.j2 - register: wireguard_ui_auth - notify: Restart WireGuard UI with podman - - name: Generate container systemd unit shell: "podman generate systemd {{ wireguard_ui_container_name }}" register: wireguard_ui_systemd_unit diff --git a/tasks/RedHat/wireguard_install.yaml b/tasks/RedHat/wireguard_install.yaml index 6581ff8..a5a4981 100644 --- a/tasks/RedHat/wireguard_install.yaml +++ b/tasks/RedHat/wireguard_install.yaml @@ -49,6 +49,6 @@ - name: Enable wg-quick systemd unit systemd: - name: wg-quick@{{ wireguard_ui_env['WGUI_CONFIG_FILE_PATH'] | basename | split('.') | first }} + name: wg-quick@{{ wireguard_ui_combined_env['WGUI_CONFIG_FILE_PATH'] | basename | split('.') | first }} enabled: yes daemon_reload: yes diff --git a/tasks/main.yaml b/tasks/main.yaml index f4c72f9..87d8aca 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -14,7 +14,7 @@ - name: Merge volumes set_fact: - wireguard_ui_combined_volumes: "{{ wireguard_ui_volumes | default([]) + [item.key +':'+ item.value] }}" + wireguard_ui_volumes: "{{ wireguard_ui_volumes | default([]) + [item.key +':'+ item.value] }}" loop: "{{ wireguard_ui_default_volumes | dict2items }}" - name: Merge ENV diff --git a/templates/users.json.j2 b/templates/users.json.j2 index 32c263b..7eab005 100644 --- a/templates/users.json.j2 +++ b/templates/users.json.j2 @@ -1,4 +1,4 @@ { - "username": "{{ wireguard_ui_env['WGUI_USERNAME'] }}", - "password": "{{ wireguard_ui_env['WGUI_PASSWORD'] }}" + "username": "{{ wireguard_ui_combined_env['WGUI_USERNAME'] }}", + "password": "{{ wireguard_ui_combined_env['WGUI_PASSWORD'] }}" } diff --git a/templates/wireguard-ui-watcher.path.j2 b/templates/wireguard-ui-watcher.path.j2 index 6635b07..42f30db 100644 --- a/templates/wireguard-ui-watcher.path.j2 +++ b/templates/wireguard-ui-watcher.path.j2 @@ -1,8 +1,8 @@ [Unit] -Description=Watch {{ wireguard_ui_env['WGUI_CONFIG_FILE_PATH'] }} for changes +Description=Watch {{ wireguard_ui_combined_env['WGUI_CONFIG_FILE_PATH'] }} for changes [Path] -PathModified={{ wireguard_ui_env['WGUI_CONFIG_FILE_PATH'] }} +PathModified={{ wireguard_ui_combined_env['WGUI_CONFIG_FILE_PATH'] }} [Install] WantedBy=multi-user.target diff --git a/templates/wireguard-ui-watcher.service.j2 b/templates/wireguard-ui-watcher.service.j2 index 557d87c..72eeb75 100644 --- a/templates/wireguard-ui-watcher.service.j2 +++ b/templates/wireguard-ui-watcher.service.j2 @@ -4,7 +4,7 @@ After=network.target [Service] Type=oneshot -ExecStart=/usr/bin/systemctl restart wg-quick@{{ wireguard_ui_env['WGUI_CONFIG_FILE_PATH'] | basename | split('.') | first }}.service +ExecStart=/usr/bin/systemctl restart wg-quick@{{ wireguard_ui_combined_env['WGUI_CONFIG_FILE_PATH'] | basename | split('.') | first }}.service [Install] RequiredBy={{ wireguard_ui_watcher_systemd_path_unit_name }}