While everyone agrees this is a good idea, there's not consensus on what's the best way to do it. Github even published a website where it keeps track of different plugins to use and paths to follow. After trying a few of them, I decided Puppet was the best tool for this task.
To manage your dotfiles with puppet, start by creating a directory for your dotfiles (I use ~/.puppet/, but you can use any name you prefer).
Make sure you have the following structure setup:
.puppet/
manifests/
default.pp
modules/
dotfiles/
manifests/
init.pp
files/
# copy your dotfiles here
.bash_profile
.vim/
As you can see, we're creating a "dotfiles" module, where we'll keep all the dotfiles we want to save. On the module's init.pp, we're going to tell Puppet where each of this files belong:
# dotfiles/manifests/init.pp
file { "/home/$id/.bash_profile":
mode => 644,
source => "puppet:///modules/bash_config/.bash_profile",
}
file { "/home/$id/.vim":
mode => 755,
ensure => directory,
recurse => true,
source => "puppet:///modules/vim_config/.vim",
}
There's a couple of things to mention from this file:
- The $id variable will be initialized by Puppet. When your script runs, it will contain the name of the user that's running the script.
- We can set file permissions with the "mode" param, which uses the chmod numeric permissions notation.
- The "source" param tells vagrant where to get the file from. It uses the special puppet:/// url scheme, which starts from the root of your puppet directory (~/.puppet on our case)
- If you want to copy an entire directory (like your .vim dir), then make sure you add "ensure => directory" and "recurse => true"
# manifests/default.pp include dotfilesNow, anytime you want to restore your dotfiles you just need to run
puppet apply --modulepath=$HOME/.puppet/modules $HOME/.puppet/manifests/default.ppAs you can see, using Puppet to manage your dotfiles is pretty straight forward. However, Puppet can do a lot more than that. I let Puppet handle almost every aspect of my configuration, from which apps should be installed up to which icons should show up on Unity's sidebar. If you want to take a look at how I achieve that, visit my .puppet repo on Github.
1 comment:
This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. web designing
Post a Comment