Hello from MCP server

List Files | Just Commands | Repo | Logs

← back |
---
- name: Install Caddy via Binary (Bypass Repo Errors)
  hosts: all
  become: yes
  vars:
    deploy_user: deploy
    caddy_version: "2.7.6" # Current stable
    site_domain: ping.pricebookplatform.com
    site_root: /var/www/ping

  tasks:
    - name: Remove broken Caddy apt repository
      file:
        path: "{{ item }}"
        state: absent
      loop:
        - /etc/apt/sources.list.d/caddy-stable.list
        - /etc/apt/sources.list.d/caddy.list

    - name: Install jq for JSON validation
      apt:
        name: jq
        state: present
        update_cache: yes

    - name: Download Caddy Binary
      get_url:
        url: "https://github.com/caddyserver/caddy/releases/download/v{{ caddy_version }}/caddy_{{ caddy_version }}_linux_amd64.tar.gz"
        dest: /tmp/caddy.tar.gz

    - name: Unarchive Caddy
      unarchive:
        src: /tmp/caddy.tar.gz
        dest: /usr/bin/
        remote_src: yes
        extra_opts: [--strip-components=0]
        creates: /usr/bin/caddy

    - name: Give Caddy permission to bind to ports 80/443
      capabilities:
        path: /usr/bin/caddy
        capability: cap_net_bind_service+ep
        state: present

    - name: Ensure directories exist
      file:
        path: "{{ item }}"
        state: directory
        owner: "{{ deploy_user }}"
        group: "{{ deploy_user }}"
        mode: '0755'
      loop:
        - "{{ site_root }}"
        - /etc/caddy
        - /var/log/caddy

    - name: Create index.html
      copy:
        dest: "{{ site_root }}/index.html"
        content: "<html><body><h1>ping</h1></body></html>"
        owner: "{{ deploy_user }}"
        group: "{{ deploy_user }}"

    - name: Setup Systemd Service
      template:
        src: caddy.service.j2
        dest: /etc/systemd/system/caddy.service
      register: service_file

    - name: Start and enable Caddy
      systemd:
        daemon_reload: yes
        name: caddy
        state: started
        enabled: yes

    - name: Restart Caddy if service file changed
      systemd:
        name: caddy
        state: restarted
      when: service_file.changed

    - name: Upload Caddy JSON configuration
      copy:
        src: config.json
        dest: /etc/caddy/config.json
        owner: "{{ deploy_user }}"
        group: "{{ deploy_user }}"
        mode: '0644'
      register: config_file

    - name: Upload Caddy API Update Script
      copy:
        src: update_caddy.sh
        dest: /usr/local/bin/update-caddy
        owner: root
        group: root
        mode: '0755'

    - name: Apply Caddy Configuration via API
      command: /usr/local/bin/update-caddy
      when: config_file.changed or service_file.changed