So I finally got around to doing something I’ve been meaning to do for a while: automating my desktop with Ansible. This has been a goal of mine for some time and thought I’d share my setup.
First, I install Ansible using brew:
brew install ansible. Then I set up a
global repo (
~/.ansible.d) for my playbooks. Then I set up a global
~/.ansible.d/site.yml file in that repo.
--- - import_playbook: base_osx.yml - import_playbook: dotfiles.yml
--- - hosts: base_osx roles: - base_osx gather_facts: False
~/.ansible.d/dotfiles.yml file is similar:
--- - hosts: dotfiles become: yes become_user: "dan" roles: - dotfiles gather_facts: False
[base_osx] 127.0.0.1 [dotfiles] 127.0.0.1 [osx_local:children] base_osx dotfiles
Then I set up my group vars. Here’s my
--- system: osx os: osx executables: brew: /usr/local/bin/brew hg: /usr/local/bin/hg zsh: /usr/local/bin/zsh directories: etc: /usr/local/etc var: /usr/local/var databases: - test_database dan: domain_name: example.com user: name: dan group: staff shell: "/usr/local/bin/zsh" template_home: home/dan home: /Users/dan system: osx ruby: version: "2.1.3" rbenv: global: "2.1.3"
mkdir -p ~/.ansible.d/roles git submodule add https://github.com/danieljaouen/ansible-base-osx ~/.ansible.d/roles/base_osx git submodule add https://github.com/danieljaouen/ansible-dotfiles ~/.ansible.d/roles/dotfiles
Then I run the
~/.ansible.d/site.yml playbook by running:
ansible-playbook -i ~/.ansible.d/inventories/osx_local ~/.ansible.d/site.yml --connection=local`
Then, after the initial setup, I cd into the
~/.dotfiles repo and run
which symlinks my dotfiles into place.
And that’s it! Hopefully you found this useful.