Chris Mague преди 8 години
ревизия
80be07a00d
променени са 7 файла, в които са добавени 128 реда и са изтрити 0 реда
  1. 4 0
      .gitignore
  2. 14 0
      README.md
  3. 34 0
      Vagrantfile
  4. 37 0
      ansible/playbook.yml
  5. 14 0
      ansible/requirements.yml
  6. 23 0
      ansible/setup.sh
  7. 2 0
      ansible/vars/main.yml

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+.vagrant/*
+*console.log
+ansible/*.retry
+ansible/roles/*

+ 14 - 0
README.md

@@ -0,0 +1,14 @@
+# Ansible-Devbox
+
+This vagrant is intended to be an example to get started using Ansible to provision
+your Development environment on vagrant.
+
+## Requirements
+
+Install vagrant and virtualbox on your machine
+
+## Running
+
+```
+vagrant up
+```

+ 34 - 0
Vagrantfile

@@ -0,0 +1,34 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+#
+
+Vagrant.configure("2") do |config|
+
+# This is going to mount your ~/Code directory
+  config.vm.synced_folder "~/Code", "/home/vagrant/Code"
+
+# Forwarding Ports - you should add any necessary ports here
+  config.vm.network "forwarded_port", guest: 2112, host: 2112
+
+# Mount the ansible dirs here and your ssh directory so we
+# can copy over your ssh keys so they can be use for code sync
+  config.vm.synced_folder "ansible/", "/etc/ansible"
+  config.vm.synced_folder "~/.ssh", "/home/vagrant/.ssh.new"
+
+# Grab the latest OS and install and configure Ansible
+  config.vm.provision "shell", inline: "/bin/bash /etc/ansible/setup.sh"
+
+  config.vm.box         = "ubuntu/trusty64"
+  config.vm.hostname    = "ansible-devbox"
+
+  config.vm.provider "virtualbox" do |v|
+    v.memory = 1024
+    v.cpus = 1
+  end
+
+# Re-download all of the modules in the requirements.yml file
+# *DANGER* do not store anything in the roles directory
+  config.vm.provision "shell", inline: "cd /etc/ansible && rm -rf roles/* && ansible-galaxy install --roles-path roles -r requirements.yml"
+  config.vm.provision "shell", inline: "/usr/local/bin/ansible-playbook /etc/ansible/playbook.yml"
+
+end

+ 37 - 0
ansible/playbook.yml

@@ -0,0 +1,37 @@
+- hosts: localhost
+  become: yes
+  become_user: root
+  become_method: sudo
+  gather_facts: yes
+  vars_files:
+  - vars/main.yml
+
+  pre_tasks:
+    - name: Update Apt Cache
+      apt: update_cache=yes cache_valid_time=86400
+      when: ansible_os_family == "Debian"
+    - name: Ubuntu Packages
+      apt: >
+        pkg={{item}}
+        state=installed
+      with_items:
+        - htop
+        - iotop
+        - git
+        - sysstat
+        - vim
+        - tmux
+        - tree
+        - tcpdump
+        - unzip
+      when: ansible_os_family == "Debian"
+
+  roles:
+    - { role: rvm_io.ruby,
+        tags: ruby,
+        become: yes,
+        rvm1_rubies: ['ruby-2.3.3'],
+        rvm1_install_flags: '--user-install',
+        rvm1_install_path: /home/vagrant/.rvm,
+        rvm1_user: vagrant
+      }

+ 14 - 0
ansible/requirements.yml

@@ -0,0 +1,14 @@
+# from galaxy
+- rvm_io.ruby
+
+#########################################################
+# Examples of other things to add
+#
+# Using SSH and a branch checks out to roles/mybranch
+# - src: git+ssh://git@github.com/myorg/shared-ansible
+#   version: mybranch
+#   name: mybranch
+
+# Grabbing a module directly from github
+# - src: https://github.com/shokunin/ansible-supervisor
+#########################################################

+ 23 - 0
ansible/setup.sh

@@ -0,0 +1,23 @@
+#!/bin/bash
+
+if [ ! -f /usr/local/bin/ansible ] ; then
+  DEBIAN_FRONTEND=noninteractive sudo apt-get update
+  DEBIAN_FRONTEND=noninteractive sudo apt-get -y upgrade
+  DEBIAN_FRONTEND=noninteractive sudo apt-get -y install python python-dev python-pip python-jinja2 python-markupsafe git
+  sudo pip install ansible > /dev/null 2>&1
+fi
+
+
+for key in `find  /home/vagrant/.ssh.new -type f -exec grep -l "PRIVATE KEY" {} \; ` ; do
+  cp $key /home/vagrant/.ssh
+  chown -R vagrant:vagrant /home/vagrant/.ssh
+done
+
+if [ ! -f /home/vagrant/.ssh.new/config ] ; then
+  echo 'Host github.com' > /home/vagrant/.ssh/config
+  echo '   StrictHostKeyChecking no' >> /home/vagrant/.ssh/config
+  echo '   UserKnownHostsFile=/dev/null' >> /home/vagrant/.ssh/config
+else
+  cp  /home/vagrant/.ssh.new/config  /home/vagrant/.ssh/config
+  chown -R vagrant:vagrant /home/vagrant/.ssh/config
+fi

+ 2 - 0
ansible/vars/main.yml

@@ -0,0 +1,2 @@
+---
+# This is where you put any variables that will override any in the galaxy modules