- name: Deploy LNBits with Poetry and configure Caddy reverse proxy hosts: vipy become: yes vars_files: - ../../infra_vars.yml - ./lnbits_vars.yml vars: lnbits_domain: "{{ lnbits_subdomain }}.{{ root_domain }}" tasks: - name: Create lnbits directory file: path: "{{ lnbits_dir }}" state: directory owner: "{{ ansible_user }}" group: "{{ ansible_user }}" mode: '0755' - name: Install required system packages apt: name: - python3.11 - python3.11-venv - python3-pip - git - curl - build-essential - pkg-config - libffi-dev state: present update_cache: yes - name: Install Poetry shell: | curl -sSL https://install.python-poetry.org | python3 - args: creates: "{{ lookup('env', 'HOME') }}/.local/bin/poetry" become: yes become_user: "{{ ansible_user }}" - name: Add Poetry to PATH lineinfile: path: "{{ lookup('env', 'HOME') }}/.bashrc" line: 'export PATH="$HOME/.local/bin:$PATH"' state: present become: yes become_user: "{{ ansible_user }}" - name: Clone LNBits repository git: repo: https://github.com/lnbits/lnbits.git dest: "{{ lnbits_dir }}/lnbits" version: main accept_hostkey: yes - name: Change ownership of LNBits directory to user file: path: "{{ lnbits_dir }}/lnbits" owner: "{{ ansible_user }}" group: "{{ ansible_user }}" recurse: yes - name: Install LNBits dependencies command: $HOME/.local/bin/poetry install --only main args: chdir: "{{ lnbits_dir }}/lnbits" - name: Copy .env.example to .env copy: src: "{{ lnbits_dir }}/lnbits/.env.example" dest: "{{ lnbits_dir }}/lnbits/.env" remote_src: yes owner: "{{ ansible_user }}" group: "{{ ansible_user }}" mode: '0644' - name: Configure LNBits environment variables lineinfile: path: "{{ lnbits_dir }}/lnbits/.env" regexp: "^{{ item.key }}=" line: "{{ item.key }}={{ item.value }}" state: present loop: - key: "LNBITS_BACKEND_WALLET_CLASS" value: "FakeWallet" - key: "LNBITS_ADMIN_UI" value: "true" - key: "HOST" value: "0.0.0.0" - key: "PORT" value: "{{ lnbits_port }}" - key: "LNBITS_DATA_FOLDER" value: "{{ lnbits_data_dir }}" - key: "LNBITS_EXTENSIONS_PATH" value: "{{ lnbits_data_dir }}/extensions" - name: Create systemd service file for LNBits copy: dest: /etc/systemd/system/lnbits.service content: | [Unit] Description=LNBits After=network.target [Service] Type=simple User={{ ansible_user }} WorkingDirectory={{ lnbits_dir }}/lnbits ExecStart=/home/{{ ansible_user }}/.local/bin/poetry run lnbits Restart=always RestartSec=30 Environment=PYTHONUNBUFFERED=1 [Install] WantedBy=multi-user.target owner: "{{ ansible_user }}" group: "{{ ansible_user }}" mode: '0644' - name: Reload systemd systemd: daemon_reload: yes - name: Enable and start LNBits service systemd: name: lnbits enabled: yes state: started - name: Ensure Caddy sites-enabled directory exists file: path: "{{ caddy_sites_dir }}" state: directory owner: root group: root mode: '0755' - name: Ensure Caddyfile includes import directive for sites-enabled lineinfile: path: /etc/caddy/Caddyfile line: 'import sites-enabled/*' insertafter: EOF state: present backup: yes - name: Create Caddy reverse proxy configuration for lnbits copy: dest: "{{ caddy_sites_dir }}/lnbits.conf" content: | {{ lnbits_domain }} { reverse_proxy localhost:{{ lnbits_port }} { header_up X-Forwarded-Host {{ lnbits_domain }} } } owner: root group: root mode: '0644' - name: Reload Caddy to apply new config command: systemctl reload caddy