I have a blog post about this project here.
Managing dotfiles and setting up a new system should be fast, reliable, and reproducible β without needing to manually install a bunch of things every time.
Ansible provides a declarative, idempotent, and powerful way to automate:
- Installing system packages
- Configuring user environments
- Managing dotfiles
- Setting up development environments across local machines, servers, and even containers.
No more "setting up" β just run the playbook and go!
Note
Previously, I had stow way of managing my dotfiles, you can find it in the other branch here: Link
You can find the demo video setting up this dotfiles configuration on multiple ubuntu homelabs here: Link
- Ansible installed
- Git
- Supported Operating Systems (for now):
- Arch Linux
- Ubuntu (maybe also for Debian, but some packages names might be different)
- (Optional) Docker, if you want to test this in a container
This repository is compatible with Ansible 2.20+ and avoids deprecated auto-injected facts. All system facts must be accessed via:
- ansible_facts["distribution"]
- ansible_facts["user_dir"]
- ansible_facts["distribution_release"]
Note
Make sure that you have ~/.local/bin in your $PATH variable as that is
where the Ansible will symlink all the bin scripts.
Run the setup script:
bash -c "$(curl -fsSL https://raw.githubusercontent.com/shricodev/dotfiles/main/bin/dotfiles)"Note
This bin/dotfiles script will auto-detect your OS, install Ansible,
setup SSH keys, and run the main playbook locally with the following.
command: ansible-playbook main.yml --limit local --ask-become-pass
You can use the dotfiles script to setup everything locally.
The dotfiles script is supposed to only run locally, but if you want to configure
dotfiles on a remote machine, go for the Taskfile tasks instead.
Make sure you update the inventory/hosts.yml file with your hosts if you plan
to use it to setup multiple systems and not just localhost.
---
all:
children:
ubuntu_homelabs:
hosts:
# <place_your_hosts_here>
local:
hosts:
localhost:
ansible_connection: localAlso, make sure that you update the group_vars/local.yml,
group_vars/all.yml and ubuntu_homelabs.yml (optional if you only plan to
run it locally) file to your liking.
First, make sure that you have task installed.
| Command | Description |
|---|---|
task docker_build |
Build the dotfiles Docker image |
task docker_run |
Run the dotfiles Docker container |
task docker_build_and_run |
Build and run the dotfiles Docker container |
task local |
Run Ansible locally (your machine) |
task ubuntu_homelabs |
Run Ansible to setup Ubuntu homelab machines |
Note
π PRO TIP: If you want to test the working without installing anything on your system, you can run the project in a docker container.
task docker_build_and_runNote
For running this to setup remote hosts, make sure you setup an SSH key to login
to each of the individual remote hosts you plan to manage and place the name in the
ansible.cfg file.
[defaults]
inventory = inventory/hosts.yml
private_key_file = <place_ssh_key_path_here>
roles_path = roles
retry_files_enabled = false
# Not the very best practice but this project just deals with local changes and
# mainly just the config changes, so shouldn't really matter.
host_key_checking = falseYou can use the dotfiles command anywhere:
bash dotfilesNote
Logs are stored in the ~/.dotfiles.log file. Use it to debug any issues.
This will:
- Verify Ansible is installed
- Clone (or update) the dotfiles repository
- Install/update any
ansible-galaxydependencies - Run the Ansible playbook with your configuration
After the first setup, a small file is created at ~/.dotfiles_first_run_check
to detect that you ran it once.
On first run:
- SSH key for Ansible is automatically generated
- Dotfiles are cloned into
~/dotfiles - Playbooks configure your system
.
βββ bin/ # Helper scripts (like 'dotfiles')
βββ pre_tasks/ # Pre-setup tasks before full playbook runs
βββ roles/ # Ansible roles for modular setup
βββ group_vars/ # Group-specific variable configurations
βββ inventory/ # Host inventory definitions
βββ collections/ # Ansible Galaxy collections
βββ configure_dotfiles.yml # Main playbook for dotfiles setup
βββ configure_system.yml # Main playbook for system setup
βββ clean_up_system.yml # Main playbook for system cleanup
βββ ansible.cfg # Ansible config file
βββ Dockerfile # Dockerfile
βββ main.yml # Master playbook entry point
βββ Taskfile.yml # Task runner file
Pull requests are welcome! Feel free to open issues for feature suggestions or bug reports.
This project is licensed under the Apache License, Version 2.0.
Happy hacking! π