dirk.ndrvn.nl

Hugo Blog Ansible Playbook

As I’m installing my new home server (Hardkernel Odroid M1S, the cheapest single-board computer with a built-in M.2 slot), I’m installing everything with an Ansible playbook. No hacking around and creating unmaintainable stuff anymore!

The premise is the same:

  - name: blog:ensure caddy can access {{ syncthing_home }}
    become: True
    ansible.posix.acl:
      path: '{{ item }}'
      entity: caddy
      etype: group
      permissions: rx
      state: present
    tags:
      - blog
      - caddy
    with_items:
      - '{{ syncthing_home }}'
      - '{{ syncthing_home }}/dirk.ndrvn.nl'

  - name: blog:ensure {{ syncthing_home }}/dirk.ndrvn.nl is setgid
    become: True
    file:
      path: '{{ syncthing_home }}/dirk.ndrvn.nl/public'
      state: directory
      group: caddy
      mode: '2775'
      recurse: yes
    tags:
      - blog

  - name: blog:ensure hugo is installed
    become: True
    apt:
      name:
        - hugo
        - inotify-tools
      state: latest
      cache_valid_time: 3600
    tags:
      - blog

  - name: blog:ensure blog public/ served
    become: True
    blockinfile:
      path: /etc/caddy/Caddyfile
      block: |
        dirk.ndrvn.nl {
          root * {{ syncthing_home }}/dirk.ndrvn.nl/public
          file_server
          # serve 404.html if file not found
          handle_errors {
            rewrite * /404.html
          }
        }        
      insertafter: "# END ANSIBLE MANAGED PREAMBLE"
      marker: "# {mark} ANSIBLE MANAGED BLOG"
    notify:
      - reload caddy
    tags:
      - blog
      - caddy
  
  - name: blog:ensure hugo-watch service is present
    become: True
    template:
      src: hugo-watch.service.j2
      dest: /etc/systemd/system/hugo-watch.service
    tags:
      - blog
  - name: blog:ensure hugo-watch is running
    become: True
    systemd:
      name: hugo-watch
      enabled: yes
      state: started
    tags:
      - blog

#Hugo #Tech #Ansible #Odroid-M1s