{"id":16179274,"url":"https://github.com/jonashackt/raspberry-ansible","last_synced_at":"2026-04-09T05:31:39.879Z","repository":{"id":52255157,"uuid":"163681288","full_name":"jonashackt/raspberry-ansible","owner":"jonashackt","description":"Setup a new Raspberry Pi 3 B+ with Ansible","archived":false,"fork":false,"pushed_at":"2021-05-12T13:15:18.000Z","size":238,"stargazers_count":71,"open_issues_count":1,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-07T11:47:17.212Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonashackt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-31T16:01:14.000Z","updated_at":"2025-02-06T11:37:32.000Z","dependencies_parsed_at":"2022-09-12T02:51:31.566Z","dependency_job_id":null,"html_url":"https://github.com/jonashackt/raspberry-ansible","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jonashackt/raspberry-ansible","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fraspberry-ansible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fraspberry-ansible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fraspberry-ansible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fraspberry-ansible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonashackt","download_url":"https://codeload.github.com/jonashackt/raspberry-ansible/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fraspberry-ansible/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31587766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T05:26:32.791Z","updated_at":"2026-04-09T05:31:39.861Z","avatar_url":"https://github.com/jonashackt.png","language":"Jinja","funding_links":[],"categories":[],"sub_categories":[],"readme":"# raspberry-ansible\nSetup a new Raspberry Pi 3 B+ with Ansible\n\nI bought a new Raspberry Pi 3 B+ and as I love to automate things, I want to automate the setup as far as possible. This repo contains my notes, what I did - maybe it is of help to you.\n\n\n### HowTo configure Raspberry headless to expose SSH\n\nI want to use my Raspberry as a home server only - so no need for Desktops whatsoever. And it will only be connected via Ethernet - directly to my Router.\n\n1. Download latest Raspbian Stretch Lite image from https://www.raspberrypi.org/downloads/raspbian/ (around 350MB) \n\n2. Unzip `2018-11-13-raspbian-stretch-lite.zip`, which will extract the image file `2018-11-13-raspbian-stretch-lite.img`\n\n3. Connect the SD card to your Mac\n\n4. Install Flash-Utility [etcher](https://www.balena.io/etcher/) (available for Mac, Win \u0026 Linux), e.g. with homebrew (see https://www.raspberrypi.org/documentation/installation/installing-images/README.md for more info)\n\n```\nbrew cask install balenaetcher\n```\n\n5. Write the image to the SD card using Etcher\n\n![flash-sd-with-etcher](screenshots/flash-sd-with-etcher.png)\n\n6. Remove and reconnect SD card to your Mac\n\n7. Enable SSH on Raspberry by creating `ssh` file on the SD card inside `/boot` directory (because by default Raspbian disables sshd, we have to enable it):\n\n```\ntouch /Volumes/boot/ssh\n```\n\n8. Remove the SD card, plug it into your Raspberry and then connect your Pi to your Network via Ethernet (additional configuration needed for Wifi). Plug in your power adapter and wait for your Pi to boot up.\n\n9. Try to connect to your Pi via SSH using `pi` user \u0026 password `raspberry`. Therefore you may need to find your Raspberry's IP at in your Router - or you try the second option:\n\n![router-raspberry-ip](screenshots/router-raspberry-ip.png)\n```\nssh pi@yourIpHere\n\n# or without IP\nssh pi@raspberrypi.local\n```\n\n10. Initial configuration\n\nRun `sudo raspi-config` to change the default password (__1 Change User Password__) and expand the file system, to make the entire space of SD card available (__7 Advanced Options / A1 Expand Filesystem__). Then go to __Finish__, which will issue a reboot.\n\n11. Copy your public key to your Pi\n\nPrereq: Have your public key available (e.g. by generating a new keypair with `ssh-keygen`)\n\n```\nssh-copy-id -i ~/.ssh/id_rsa.pub pi@raspberrypi.local\n```\n\n\n### Install Docker with Ansible\n\nRun the Ansible playbook with:\n\n```\nansible-playbook rpi-nextcloud.yml -i hosts\n```\n\n\n### Install Next-Cloud with Ansible \u0026 Docker\n\nSee https://hub.docker.com/_/nextcloud/\n\nChoose an appropriate `docker-compose.yml` for you - this one may be a good choice, as it inherits an front-end reverseproxy \u0026 let's encrypt for security reasons, alongside a Postgres for your data, that can easily backuped later:\n\nhttps://github.com/nextcloud/docker/blob/master/.examples/docker-compose/with-nginx-proxy/postgres/apache/docker-compose.yml\n\nMariaDB didn't work for me, as it wasn't able to pull the MariaDB docker image (maybe this image isn't available for `armhf` any more?)\n\n```\n$ sudo docker pull mariadb\nUsing default tag: latest\nlatest: Pulling from library/mariadb\nno matching manifest for unknown in the manifest list entries\n```\n\nHere's my [docker-compose.yml](nextcloud/templates/docker-compose.yml.j2) - I don't like the `*.env` files and have those environment variables inside my `docker-compose.yml` and the values (later) in Ansible group_vars:\n\n```\nversion: '3'\n\nservices:\n  db:\n    image: postgres:alpine\n    restart: always\n    volumes:\n      - db:/var/lib/postgresql/data\n    environment:\n      - POSTGRES_PASSWORD=\n      - POSTGRES_DB=nextcloud\n      - POSTGRES_USER=nextcloud\n\n  app:\n    image: nextcloud:apache\n    restart: always\n    volumes:\n      - nextcloud:/var/www/html\n    environment:\n      - VIRTUAL_HOST=\n      - LETSENCRYPT_HOST=\n      - LETSENCRYPT_EMAIL=\n      - POSTGRES_HOST=db\n      - POSTGRES_PASSWORD=\n      - POSTGRES_DB=nextcloud\n      - POSTGRES_USER=nextcloud\n    depends_on:\n      - db\n    networks:\n      - proxy-tier\n      - default\n\n  proxy:\n    build: ./proxy\n    restart: always\n    ports:\n      - 80:80\n      - 443:443\n    labels:\n      com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: \"true\"\n    volumes:\n      - certs:/etc/nginx/certs:ro\n      - vhost.d:/etc/nginx/vhost.d\n      - html:/usr/share/nginx/html\n      - /var/run/docker.sock:/tmp/docker.sock:ro\n    networks:\n      - proxy-tier\n\n  letsencrypt-companion:\n    image: jrcs/letsencrypt-nginx-proxy-companion\n    restart: always\n    volumes:\n      - certs:/etc/nginx/certs\n      - vhost.d:/etc/nginx/vhost.d\n      - html:/usr/share/nginx/html\n      - /var/run/docker.sock:/var/run/docker.sock:ro\n    networks:\n      - proxy-tier\n    depends_on:\n      - proxy\n\nvolumes:\n  db:\n  nextcloud:\n  certs:\n  vhost.d:\n  html:\n\nnetworks:\n  proxy-tier:\n\n```\n\n\n# Molecule?\n\n### Use Molecule with Ansible to develop a role for your Pi\n\nNow we have SSH running, we should be able to use Ansible with our Raspi! As we are developing infrastructure code, we shouldn't miss to make use of [Test-driven development (TDD)](https://en.wikipedia.org/wiki/Test-driven_development) - therefore we also use Molecule \u0026 Testinfra. If you don't know them, read this post about [Test-driven infrastructure development with Ansible \u0026 Molecule](https://blog.codecentric.de/en/2018/12/test-driven-infrastructure-ansible-molecule/) and come back here.\n\nBe sure to have Ansible \u0026 Molecule installed. As we need to have a testing infrastructure ready, we should install Docker too. Use the package manager of your choice for Ansible \u0026 Docker but always use `pip` for Molecule (and for `docker-py`, which is needed for Molecule + Docker integration)\n\n```\nbrew install ansible\nbrew install docker\nbrew install python\npip3 install molecule\npip3 install docker-py\n```\n\nNow let's initiate a new Ansible role skeleton with Molecule:\n\n```\nmolecule init role --driver-name docker --role-name rpi-nextcloud --verifier-name testinfra\n```\n\nAs we need to emulate a PI on our Mac/Win/Linux machine to test what we're doing with Ansible, we need to keep in mind that a Raspberry uses ARM instead of x86/amd64 architecture! So we need a Docker image, that is based on ARM. Luckily there is [resin/rpi-raspbian](https://hub.docker.com/r/resin/rpi-raspbian/), which is maintained quite well. We could have also started with [HyperiotOS](https://blog.hypriot.com/getting-started-with-docker-on-your-arm-device/), which is also a great starting point. But then we also need to flash this as the Raspberry image already at the beginning - maybe I'll give it a try later, for now I'll stick to the standard raspbian image.\n\nSo let´s change the Docker image inside our [molecule.yml](docker/molecule/default/molecule.yml):\n\n```\nscenario:\n  # default scenario is Docker\n  name: default\n\ndriver:\n  name: docker\nplatforms:\n  - name: docker-rpi\n    image: resin/rpi-raspbian\n    privileged: true\n\nprovisioner:\n  name: ansible\n  lint:\n    name: ansible-lint\n    enabled: false\n  playbooks:\n    prepare: prepare-docker-in-docker.yml\n    converge: ../playbook.yml\n\nlint:\n  name: yamllint\n  enabled: false\nverifier:\n  name: testinfra\n  directory: ../tests/\n  env:\n    # get rid of the DeprecationWarning messages of third-party libs,\n    # see https://docs.pytest.org/en/latest/warnings.html#deprecationwarning-and-pendingdeprecationwarning\n    PYTHONWARNINGS: \"ignore:.*U.*mode is deprecated:DeprecationWarning\"\n  lint:\n    name: flake8\n  options:\n    # show which tests where executed in test output\n    v: 1\n\n```\n\n### Install Docker on our Raspi emulated with Docker (Docker-in-Docker)\n\nAs described in [Continuous Infrastructure with Ansible, Molecule \u0026 TravisCI](https://blog.codecentric.de/en/2018/12/continuous-infrastructure-ansible-molecule-travisci/) we also need to install Docker in Docker. Add the [prepare-docker-in-docker](docker/molecule/default/prepare-docker-in-docker.yml) as described in the post and rebuild your project to Molecule multi scenario style (enhance the docs here!).\n\n`cd` into `rpi-nextcloud` and run:\n\n```\nmolecule --debug create\n```\n\n### Latest state (13.01.2019):\n\nThere are Qemu problems - seem that Docker is unable to fully emulate `armhf`:\n\n```\n$ docker exec -it 44 sh\n# docker ps\nqemu: uncaught target signal 4 (Illegal instruction) - core dumped\nIllegal instruction\n```\n\n\n### Switch over to Hyperiot OS\n\nSo it's not that easy to emulate the Docker installation on an x86 hardware (like MacOS) - so the whole Molecule idea for the Docker installation would lead to an custom Molecule driver development for Qemu (see https://gist.github.com/hfreire/5846b7aa4ac9209699ba for example).\n\nFor now I don't have that much time, so I'll go with the great Docker-enabled Raspbian releases from \n\n\n# Links\n\n* https://medium.com/@viveks3th/how-to-bootstrap-a-headless-raspberry-pi-with-a-mac-6eba3be20b26\n* https://github.com/yusekiya/raspi3_setup\n* https://hackernoon.com/raspberry-pi-headless-install-462ccabd75d0","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fraspberry-ansible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonashackt%2Fraspberry-ansible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fraspberry-ansible/lists"}