Home

ENG - Home SmartCenter

linux debian ansible

This post aims to log how to setup a small pc (fanless pc, o a raspberry pi) providing some usefull service on your local network.

Home center simple example

During the past weeks I posted those notes about those roles:

Here an use case follows, where all them are used together.

---
- hosts: smart_center
  become: yes
  roles:
    - common
    - docker
    - nginx
  vars:
    insecure_registries: "\"center.home.local:5000\""
    ansible_ssh_public_key_file: "{ { lookup('file', '{ { playbook_dir } }/keys/admin.pub') } }"
    snapshot_public_key: "{ { lookup('file', '{ { playbook_dir } }/keys/snapshot.pub') } }"
    portainer_enable: true
    nginx_vhosts:
      - { domain: "portainer.home.local", file: "{ { playbook_dir } }/files/nginx-vhosts/portainer.home.local", enabled: true, ssl: false }
      - { domain: "dns.home.local", file: "{ { playbook_dir } }/files/nginx-vhosts/dns.home.local", enabled: true, ssl: false }
      - { domain: "torrent.home.local", file: "{ { playbook_dir } }/files/nginx-vhosts/torrent.home.local", enabled: true, ssl: false }
    active_containers:
      - name: 'transmission'
        image: 'lscr.io/linuxserver/transmission:arm64v8-latest'
        volumes:
          - /etc/localtime:/etc/localtime:ro
          - /media/data/transmission/downloads:/downloads
          - /media/data/transmission/config:/config
          - /media/data/transmission/watch:/watch
        ports:
          - 0.0.0.0:9091:9091
          - 0.0.0.0:51413:51413
          - 0.0.0.0:51413:51413/udp
        env:
          PUID=1000
          PGID=1000
          #TRANSMISSION_WEB_HOME= #optional
          #USER= #optional
          #PASS= #optional
          #WHITELIST= #optional
          #PEERPORT= #optional
          #HOST_WHITELIST= #optional
        restart_policy: "unless-stopped"
      - name: pihole
        image: pihole/pihole:latest
        ports:
          - 0.0.0.0:53:53/tcp
          - 0.0.0.0:53:53/udp
          - 0.0.0.0:67:67/udp # Only required if you are using Pi-hole as your DHCP server
          - 0.0.0.0:8083:80/tcp
        env:
          TZ: "Europe/Rome"
          WEBPASSWORD: changeme
        volumes:
          - /srv/pihole/etc:/etc/pihole
          - /srv/pihole/dnsmasq:/etc/dnsmasq.d
        capabilities:
          - NET_ADMIN # Required if you are using Pi-hole as your DHCP server, else not needed
        restart_policy: unless-stopped
      - name: registry
        image: registry:2
        ports:
          - 0.0.0.0:5000:5000/tcp
        volumes:
          - /etc/localtime:/etc/localtime:ro
          - /media/data/docker-registry/:/var/lib/registry
        restart_policy: unless-stopped

After you run this playbook you have setup:

Next step - custom service

Next step consists of:

The service I now we need is a git server: simple-git-srv

Build the image

The process can be summarized as:

# clone the code
$ git clone https://github.com/stethewwolf/docker_simple-git-srv.git

# step in the project folder
$ cd docker_simple_git_srv

# build the docker image
$ docker build . -t simple-git-server

# tag the image
$ docker tag simple-git-server center.home.local:5000/simple-git-server

# push the image
$ docker push center.home.local:5000/simple-git-server

Deploy the service

Add to nginx_vhosts:

- { domain: "git.home.local", file: "{ { playbook_dir } }/files/nginx-vhosts/git.home.local", enabled: true, ssl: false }

Add to active_containers

 - name: 'git-srv'
   image: 'center.home.local:5000/simple-git-server'
   volumes:
     - /etc/localtime:/etc/localtime:ro
     - git-srv-ssh:/etc/ssh
     - /srv/git:/var/lib/git
   env:
     GIT_ADMIN: 'stethewwolf'
   ports:
     - 0.0.0.0:2222:22
     - 127.0.0.1:8080:80
   restart_policy: "unless-stopped"

Then run ansible-playbook as done before.

Riferimenti