Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable Vagrant Box for Builds #779

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,7 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk

# Vagrant
/.vagrant
/.ansible-roles
Expand Down
34 changes: 34 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[defaults]
retry_files_enabled = false
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: vagrant-base
src: naftulikay.vagrant-base
58 changes: 58 additions & 0 deletions vagrant.yml
Original file line number Diff line number Diff line change
@@ -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