From b61c996bd376079703e0f81214f372cf79ee5ebc Mon Sep 17 00:00:00 2001 From: Naftuli Kay Date: Fri, 30 Jun 2017 22:44:51 -0700 Subject: [PATCH] Reusable Vagrant Box for Builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because portability is king™. --- .gitignore | 4 ++++ Vagrantfile | 34 ++++++++++++++++++++++++++++ ansible.cfg | 2 ++ requirements.yml | 3 +++ vagrant.yml | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 Vagrantfile create mode 100644 ansible.cfg create mode 100644 requirements.yml create mode 100644 vagrant.yml diff --git a/.gitignore b/.gitignore index 7211dc8c0..7f1e15dd4 100644 --- a/.gitignore +++ b/.gitignore @@ -145,3 +145,7 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk + +# Vagrant +/.vagrant +/.ansible-roles diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 000000000..543c1044a --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- +# vi: set ft=ruby : + +require 'shellwords' + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + # Every Vagrant virtual environment requires a box to build off of. + config.vm.box = "bento/centos-7.3" + config.vm.hostname = "devel" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + config.vm.network "private_network", type: "dhcp" + + # Tweak the VMs configuration. + config.vm.provider "virtualbox" do |vb| + vb.memory = 1024 + vb.linked_clone = true + end + + # Configure the VM using Ansible + config.vm.provision "ansible_local" do |ansible| + ansible.galaxy_role_file = "requirements.yml" + ansible.galaxy_roles_path = ".ansible-roles" + ansible.provisioning_path = "/vagrant" + ansible.playbook = "vagrant.yml" + # allow passing ansible args from environment variable + ansible.raw_arguments = Shellwords::shellwords(ENV.fetch("ANSIBLE_ARGS", "")) + end +end diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 000000000..58bbad17a --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +retry_files_enabled = false diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 000000000..f494baf9c --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +--- +- name: vagrant-base + src: naftulikay.vagrant-base diff --git a/vagrant.yml b/vagrant.yml new file mode 100644 index 000000000..76ce91f77 --- /dev/null +++ b/vagrant.yml @@ -0,0 +1,58 @@ +--- +- hosts: all + become: true + vars: + node_version: "6.11.0" + roles: [vagrant-base] + tasks: + - name: check if node is installed + command: ls /usr/local/node-{{ node_version }}/bin + register: node_result + failed_when: false + changed_when: false + + - name: set node facts + set_fact: + node_installed: "{{ node_result.rc == 0 | bool }}" + node_shared_dir: /usr/local/node + node_install_dir: "/usr/local/node-{{ node_version }}" + + - name: create node installation directory + file: path={{ node_install_dir }} state=directory mode=0755 owner=root group=root + + - name: download node + unarchive: + src: https://nodejs.org/dist/v{{ node_version }}/node-v{{ node_version }}-linux-x64.tar.xz + remote_src: true + dest: "{{ node_install_dir}}" + extra_opts: ["--strip-components", "1"] + when: not node_installed + + - name: create node installation symlink + file: + src: "{{ node_install_dir }}" + dest: "{{ node_shared_dir }}" + owner: root + group: root + state: link + + - name: create node executable symlinks + file: + src: "{{ node_install_dir }}/bin/{{ item }}" + dest: "/usr/local/bin/{{ item }}" + owner: root + group: root + state: link + with_items: + - node + - npm + + - name: create environment profile for node + copy: + content: | + #!/usr/bin/env bash + export PATH="$PATH:{{ node_shared_dir }}/bin" + dest: /etc/profile.d/99-node.sh + owner: root + group: root + mode: 0755