Possible to fully automate re-installing my homelab server (os included) with ansible? reddit / selfhosted ---------------------------------------------------------------------- Generic_User48579 · 2023-12-29 16:56 Hey guys, I have ubuntu desktop running on my server. I made basic configuration changes, small stuff like turning remote desktop on. I have loads of services running as docker containers with portainer. I have LinuxGSM servers running on my server directly. I created 6-8 nfs shares from my NAS to my Server. I modified my firewall. This is already quite a bit of customizing. Now I also want to expose some services to the internet, which means I want to harden my server first, which means even more customization. I thought it would be great if I could automate all this so that I can nuke my server and rebuild it at my leisure, without going through all the configurations manually again and forgetting stuff. Ive heard of ansible and thought that sounds great. I have learned ansible works for anything that can be ssh-ed into. So ig I only need to install ubuntu desktop manually, make sure ssh is installed and my ssh credentials match the ones in my ansible playbook and the rest can be automated with ansible. But is there a way/program to automate the initial ubuntu or some other linux os installation? Something that I grant access to my homelab server, tell it what to do, and then it installs the OS I chose, maybe even sets up ssh so ansible can take over? Does this sound doable? What are possible options to do this? Heads up, I don't want to turn my homelab server into a vm. I might play around with running a vm or two on my server for fun but most of my homelab should run on the host os itself. If I went the vm route my server itself would need to have an OS to run this vm on, which means another dirty os that is manually installed and configured, another factor for potential issues etc. ---------------------------------------------------------------------- bozho · 2023-12-29 17:58 Ubuntu supports unattended installs. [This](https://ubuntu.com/server/docs/install/autoinstall) looks like a good place to start. Regarding Ansible, you are correct. Anything you configure/install manually, you can do it via Ansible (worst case scenario, you run shell commands using `shell` or `command` modules). As long as you can ssh into a machine and the machine has python 3 installed, you're golden (Ansible can even bootstrap python installation if needed). Do look into Ansible's check mode - it's a kind of a dry run that checks whether everything is configured as your playbook would configure it (in "configuration as code", this is often known as "configuration drift"). The check mode will tell you what your playbook will (re)configure when you do a regular run. While most Ansible modules work well in the check mode, you need to take some care when using `shell`/`command` and some other modules. Ideally, an Ansible task should execute only when needed and report back as having changed something (e.g. a `user` task to create a user will only execute if the user does not exist). `shell`/`command` modules will always execute specified commands, unless you use the `when` clause on the task. In order to follow the ideal approach, you'd have a task that will determine if your shell task needs to run or write your shell command in such a way to return a value indicating whether it performed a change or not (Ansible task output can be captured using the `register` clause and when used in `changed_when` clause to indicate to Ansible engine if the task performed a configuration change or not). The above is not absolutely necessary in a homelab, but if your playbook properly supports the check mode, it will spare you surprise config changes :-) ---------------------------------------------------------------------- blind_guardian23 · 2023-12-30 11:01 Usually u dont use desktop Versions because the greater memory footprint and higher profile. SSH is enough for managing the host, even better if ansible does the job. I have written a set of roles to manage Linux servers: https://github.com/selfhostx/ansible/tree/main/roles interesting for your need are computer_instance : VM creating with cloud-init and Proxmox (which i highly recommend) and baserole (initial configuration of the system like users etc.).