Skip to content

Instantly share code, notes, and snippets.

@athaller
Forked from jbgo/Vagrantfile
Created January 13, 2016 04:54
Show Gist options
  • Save athaller/afce834581b07331acb2 to your computer and use it in GitHub Desktop.
Save athaller/afce834581b07331acb2 to your computer and use it in GitHub Desktop.
Getting started with ansible on OS X

You will need python 2.6 or greater. OS X ships with python 2.7.

You can use pip to install the python packages required for ansible. Here's how to install it if you don't have it already.

sudo easy_install pip
sudo pip install paramiko PyYAML jinja2

Now you can install ansible:

sudo pip install ansible

NOTE: Maybe if I used the homebrew python packages, I wouldn't have to do all this sudo nonsense...

Set up a vagrant VM to test ansible with. Make sure you are running the latest version of Vagrant!

mkdir -p ~/projects/ansible-rails
cd ~/projects/ansible-rails
vagrant init

Edit your vagrant file, Vagrantfile to match the one in this gist.

Install your SSH public key on the vagrant box. This is simple with ssh-copy-id. You can install it via homebrew if you haven't already.

[15:38:54] ../ansible-rails $ brew install ssh-copy-id
==> Downloading http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-6.2p1.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/ssh-copy-id/6.2p1: 7 files, 180K, built in 2 seconds

Copy the SSH key to your vagrant box. You will need to type the password (vagrant) at this step.

[15:39:08] ../ansible-rails $ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

If everything went smoothly, you should be able to log in without being prompted for a password.

[15:39:34] ../ansible-rails $ ssh [email protected]
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Sun Aug 18 20:30:26 2013 from 192.168.33.1
vagrant@precise64:~$

Add your VM's IP to the /etc/ansible/hosts file. You will need to create it. The file is included in this gist.

TODO: find out if there's another place I can store this file on my local machine that doesn't require sudo access.

sudo mkdir -p /etc/ansible
sudo vi /etc/ansible/hosts

Now if everything is setup correctly, you should be able to ping the vagrant box using ansible.

[15:44:07] ../ansible-rails $ ansible all -m ping
[email protected] | success >> {
    "changed": false,
    "ping": "pong"
}

Hooray! Now to setup a rails stack with ansible...

# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "192.168.33.10"
config.ssh.forward_agent = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment