Skip to content

Instantly share code, notes, and snippets.

@base10
Last active January 3, 2016 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save base10/8408976 to your computer and use it in GitHub Desktop.
Save base10/8408976 to your computer and use it in GitHub Desktop.
Vagrant/Ansible bootstrap
user_acct: "{{ lookup('env','USER') }}"
# created with:
# python -c 'import crypt; print crypt.crypt("foobarbaz", "$1$SomeSalt$")'
# nb: use this on a linux machine. OS X doesn't yield the same
user_pass: "$1$SomeSalt$3/ECY6goYQn6IDk/S6QC91"
shell: "/bin/bash"
---
- name: vagrant bootstrap play
hosts: vagrant
user: vagrant
sudo: yes
gather_facts: true
vars_files:
- group_vars/all
tasks:
- name: add groups
group: >
name=$item
state=present
with_items:
- developer
- build
- www
- sudo
- name: add user
user: >
name={{ user_acct }}
createhome=yes
shell={{shell}}
password={{user_pass}}
groups=developer,build,www,sudo
state=present
- name: set ssh dir
file: >
path=/home/{{ user_acct }}/.ssh
state=directory
owner={{ user_acct }}
mode=0700
- name: provision ssh keys
authorized_key: >
user={{ user_acct }}
key="{{ lookup('file', 'item') }}"
with_first_found:
- $ENV('HOME')/.ssh/id_rsa.pub
- $ENV('HOME')/.ssh/id_dsa.pub
[all:vars]
ansible_connection=ssh
[vagrant]
172.16.3.10
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# NB: This is a V2 file. Vagrant 1.2 or later is required for the
# Ansible provisioner
config.vm.define :db do |db|
db.vm.box = "core-ubuntu-12.04.2"
db.vm.box_url = "http://example.com/vagrants/core-ubuntu-12.04.2.box"
db.vm.hostname = "vagrant.local"
db.vm.network :private_network, ip: "172.16.3.10"
db.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "512"]
end
db.vm.provision :ansible do |ansible|
ansible.playbook = "vagrant_bootstrap.yml"
ansible.inventory_path = "vagrant_hosts"
ansible.verbose = true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment