DEV Community

Cover image for How I Manage my System and Dotfiles (with Ansible) πŸ”₯

How I Manage my System and Dotfiles (with Ansible) πŸ”₯

Shrijal Acharya on April 28, 2025

The Problem πŸ€• Wait... before I share the problem with you, I first need to make sure that you're on the right machine. I assume you are ...
Collapse
 
nabin_bd01 profile image
Nabin Bhardwaj

I've been using stow for dotfiles management. I don't manage a lot of tools myself. It's been working pretty solid. System management isnt really needed for me as I usually work with Windows.

Thank you for sharing this idea of using Ansible for dotfiles management by the way!

Collapse
 
dijaydas12 profile image
Bijay Das

That's the way!!

Collapse
 
shricodev profile image
Shrijal Acharya

πŸ”₯

Collapse
 
shricodev profile image
Shrijal Acharya

Thanks, Nabin! πŸ™Œ
Glad you enjoyed this one.

Collapse
 
moopet profile image
Ben Sinclair

I use stow with a small shell script to install packages I like, depending on OS. It's like, "do we have pacman? Do we have apt? is there a dumb Applications directory you need magic powers to access?" and then "install list-of-stuff".

Collapse
 
shricodev profile image
Shrijal Acharya

Yeah, stow is pretty solid and does almost all the work and combined with sh as you said, that's the way it's supposed to be. And with this new setup that I have with Ansible, it's pretty much the same but the "Ansible" way yk.

BTW, it's good to see you here, man. πŸ™Œ

Collapse
 
dijaydas12 profile image
Bijay Das

This looks awesome. I store my config on github and no other tool.

Collapse
 
williamdk profile image
Asaba William

I'm curious to about this

Collapse
 
shricodev profile image
Shrijal Acharya

Thank You, @williamdk πŸ™Œ
Let me know if you give this a shot!

Collapse
 
shricodev profile image
Shrijal Acharya

Try this out and let me know how it goes for you!

Collapse
 
nevodavid profile image
Nevo David

Pretty cool seeing someone actually wrangle dotfiles and system setup like this - you think most people ever stick with one config, or are we all just endlessly tweaking forever?

Collapse
 
shricodev profile image
Shrijal Acharya

Thank you, Nevo! I don't know about anybody else, but for me, my dotfiles change every 2-3 days with just a little tweak. I'm never satisfied with one config. πŸ˜‚

Collapse
 
areeba_nishat_5d9b045adcd profile image
Areeba Nishat

That sounds like a solid setup! Leveraging a dotfiles repo combined with something like Ansible for full system provisioning is a huge step up from just using GNU Stowβ€”it brings real automation and reproducibility to your environments. It's especially handy when spinning up new machines or VMs, whether locally or in the cloud.

Here are a few suggestions you might consider as you refine your workflow:

Modular Ansible Roles: Break your setup into reusable roles (e.g., dev-tools, terminal, neovim, etc.) so you can apply them selectively based on the machine type (e.g., dev machine vs. server).

Use Tags in Ansible: This allows you to run only certain parts of your playbook (e.g., --tags "dotfiles" or --tags "packages"), which makes testing and updates much easier.

Secrets Management: If you need to manage sensitive data (like SSH keys, API tokens), consider integrating tools like Ansible Vault or sops.

Cross-Platform Support: If you're using both Linux and macOS (or even WSL), you could structure your playbooks to adapt per platform with when: conditions.

CI for Dotfiles: You could even use GitHub Actions or another CI to lint/test your Ansible playbooks or even do dry runs on containerized environments to catch issues before you apply them.

You're on the right path. Once it’s dialed in, a single command to bootstrap your entire environment is a massive time-saver

Collapse
 
areeba_nishat_5d9b045adcd profile image
Areeba Nishat

Managing your development environment across multiple machines can quickly become messy β€” especially when you have dozens of tools, configurations, and preferences. That’s why I use Ansible to manage my system setup and dotfiles in a clean, repeatable, and version-controlled way.

Collapse
 
aayyusshh_69 profile image
Aayush Pokharel

Kadaich sathiii!! 😍

Collapse
 
shricodev profile image
Shrijal Acharya

Thank you, my friend! πŸ€—

Collapse
 
shricodev profile image
Shrijal Acharya

Share your thoughts in the comments! :D

Collapse
 
shricodev profile image
Shrijal Acharya

Here's the post on Reddit: reddit.com/r/ansible/comments/1k9x...

Collapse
 
larastewart_engdev profile image
Lara Stewart - DevOps Cloud Engineer

This can backfire. I don't think Ansible has all the modules that you might require in the future to manage your system. But, this is a great approach to solving the issue at hand. πŸ‘

Collapse
 
shricodev profile image
Shrijal Acharya

Thank you! There's shell support, though, which I think should be enough to get just what I want, even if there's no module support for it.

Collapse
 
sawata_2_shayne profile image
Shayne Villarin

My team on a small school project once had to work with Ansible for network management. It was really a challenge back then. Interesting to see more use cases for this. πŸ’’

Collapse
 
shricodev profile image
Shrijal Acharya

That's great to hear. Thank You, Shayne! Ansible's great, and I've also recently started using it. Keep rocking!! πŸ”₯

Collapse
 
sunoxuqe profile image
Suno Xuqe

From reddit. Great approach for managing config files and folders.

Collapse
 
shricodev profile image
Shrijal Acharya

Thanks!

Collapse
 
areeba_nishat_5d9b045adcd profile image
Areeba Nishat

Managing your system configuration and dotfiles efficiently is crucial for both developers and system administrators. With the right tools, you can automate your setup, streamline workflows, and ensure consistency across multiple machines. Ansible is a powerful tool for managing systems, and it's perfect for automating the management of dotfiles and configurations.

What are Dotfiles?
Dotfiles are configuration files for various programs, like .bashrc, .vimrc, .gitconfig, etc. They are typically hidden files that start with a dot (.) in Unix-like operating systems. These files store your personalized configurations and settings for different applications.

Collapse
 
areeba_nishat_5d9b045adcd profile image
Areeba Nishat

Managing a Linux system across multiple devices can be a challenge β€” especially when you want consistency in your development environment. That’s where Ansible comes in.

In this post, I’ll walk you through how I use Ansible to manage my system and dotfiles, making my system setup reproducible, fast, and version-controlled.

Why Ansible?
Ansible is a powerful configuration management tool that:

Is agentless (uses SSH)

Works cross-platform (ideal for Linux/macOS)

Uses human-readable YAML files

Can manage both dotfiles and system packages

Directory Structure
Here’s a simplified version of my Ansible setup:

bash
Copy
Edit
ansible/
β”œβ”€β”€ inventory
β”‚ └── hosts
β”œβ”€β”€ playbook.yml
β”œβ”€β”€ roles/
β”‚ β”œβ”€β”€ dotfiles/
β”‚ └── packages/
inventory/hosts: Defines your target systems (localhost or remote).

playbook.yml: The main file to run your setup.

roles/: Contains reusable components for dotfiles and packages.

Managing Dotfiles
I keep all my dotfiles (like .bashrc, .vimrc, .gitconfig) in a Git repo and symlink them via Ansible:

yaml
Copy
Edit

roles/dotfiles/tasks/main.yml

  • name: Clone dotfiles repository
    git:
    repo: 'github.com/myusername/dotfiles.git'
    dest: '{{ ansible_env.HOME }}/.dotfiles'

  • name: Symlink .bashrc
    file:
    src: '{{ ansible_env.HOME }}/.dotfiles/bashrc'
    dest: '{{ ansible_env.HOME }}/.bashrc'
    state: link
    force: yes
    This ensures consistency every time I set up a new machine.

Installing Packages
I define all essential packages in one place:

yaml
Copy
Edit

roles/packages/tasks/main.yml

  • name: Install essential packages apt: name:
    • git
    • vim
    • curl
    • htop state: present You can easily adapt this for other package managers like brew, dnf, or pacman.

Running the Playbook
To apply the setup:

bash
Copy
Edit
ansible-playbook -i inventory/hosts playbook.yml
That’s it β€” your environment is ready in minutes!

Benefits I Get
Consistent dev environment across devices

No need to remember what to install/configure

Faster setup for fresh installs or new machines

Easily updatable dotfiles with Git

Collapse
 
kiponos profile image
Devops Kiponos

Clever work you’ve done there.

Collapse
 
shricodev profile image
Shrijal Acharya

Heh, I try! Appreciate it πŸ™Œ