--- layout: ../../layouts/BlogLayout.astro --- # Agent-less infrastructure management with Ansible :ansible: As I explore new things and grow my homelab :raspberry-pi: infrastructure things start to get a little messy. I've reached the point where I should start using more advanced deployment strategy than just manually setting up servers via SSH or `rsync`-ing a bunch of files into them. The goal is to reach [Infrastructure as Code](https://en.wikipedia.org/wiki/Infrastructure_as_code). # But what about Docker? :whale: [Docker](https://www.docker.com/) is an amazing tool that solves particularly nasty problem - isolating your application from environment and **reliably** running it on any platform. You just pack your application into the container and ship it anywhere you want! It makes your app **scalable**! I use Docker on my daily job and I can't imagine it otherwise. But here, in my tiny homelab (which is just one RaspberryPI :raspberry-pi: at this point), this is not world-class production problems, so it might be an overkill. Docker requires your servers to run a *daemon* - e.g extra software layer (and it's dependencies) between your applications and the metal. It will run in the background and make your fan work a bit louder :helicopter: in the upcoming summer nights to compensate for those extra couple degrees. ![meme](/public/docker-on-rpi.jpg) # Introducting Ansible :ansible: [Here it comes](https://ansible.com) - **agent-less** deployment tool that doesn't require your server to run anymore bullshit than good old Python :python: and open SSH port. In Ansible you define so called playbooks - `YAML` specs of your tasks. Then you just feed the `YAML` to `ansible-playbook` and voila! It's already SSHing into your machines and doing your job now! Ansible is not the tool you should learn, it's so simple that you can use it right away! # Examples from my infrastructure :raspberry-pi: Ansible has a bunch of built-in convenience commands that make your life even more enjoyable. ![meme](/public/pepe-smug.png) This is how easy it is to setup a cron-job: ```YAML - name: Setup auto-renewing certificates become: true cron: name: "Auto-renew certificates" minute: "0" hour: "12" job: "/usr/bin/certbot renew --quiet" ``` Transferring files: ```YAML - name: Copy nginx configuration become: true copy: src: ./files/nginx/website dest: /etc/nginx/sites-available ``` Installing packages: ```YAML - name: Install build tools apt: pkg: - gcc - make - cmake - gnutls-dev - uuid-dev ``` ...and many many more. Check out source code of my playbooks here: - https://git.eug-vs.xyz/eug-vs/infrastructure/ The notable ones are: - Installing [taskd](https://git.eug-vs.xyz/eug-vs/infrastructure/tree/taskd.yaml) (migth be worth a separate post) - Installing [git server along with cgit](https://git.eug-vs.xyz/eug-vs/infrastructure/tree/git-server.yaml)