Skip to content

Commit

Permalink
PBs: Added PB for setting up vagrant machines
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Parker committed Nov 7, 2019
1 parent f1d05cb commit 8d48a2c
Showing 1 changed file with 155 additions and 0 deletions.
155 changes: 155 additions & 0 deletions ansible/playbooks/vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
########################################
# AdoptOpenJDK - Ansible Playbook for: #
# ------------- Vagrant --------------#
########################################

- hosts: all
remote_user: root
become: yes

tasks:
- block:
- name: Apt install Prerequisites
apt:
name: ['software-properties-common','tree']
update_cache: yes

- name: Run apt-get upgrade
apt: upgrade=safe

- name: Check tmp folder exists
stat:
path: /tmp
register: tmp_folder

- name: Create tmp folder if necessary
file:
path: /tmp
state: directory
when: tmp_folder.stat.isdir is not defined

###########
# Ansible #
###########

- name: Check if Ansible is installed
shell: which ansible >/dev/null 2>&1
ignore_errors: yes
register: ansible_installed

- name: Add Ansible repository
apt_repository:
repo: ppa:ansible/ansible
when: ansible_installed.rc != 0

- name: Install Ansible
apt:
name: ansible
update_cache: yes
when: ansible_installed.rc != 0

#######
# Git #
#######

- name: Check if Git is installed
shell: git --version >/dev/null 2>&1
ignore_errors: yes
register: git_installed

- name: Test if Git is installed at the correct version
shell: git --version | sed -e 's/git version //g' | awk -F'[.]' '{print $1 "." $2}'
when: git_installed.rc == 0
register: git_version

- name: Download Git Source
get_url:
url: https://www.kernel.org/pub/software/scm/git/git-2.15.0.tar.xz
dest: /tmp/git-2.15.0.tar.xz
mode: 0440
when:
- (git_installed.rc != 0 ) or (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt') )

- name: Extra Git Source
unarchive:
src: /tmp/git-2.15.0.tar.xz
dest: /tmp/
copy: False
when:
- (git_installed.rc != 0 ) or (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt') )

- name: Compile and Install Git from Source
shell: cd /tmp/git-2.15.0 && ./configure --prefix=/usr/local --without-tcltk && make clean && make -j {{ ansible_processor_vcpus }} && sudo make install
become: yes
when:
- (git_installed.rc != 0 ) or (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt') )

- name: Remove system git if needed
apt:
name: git
state: absent
when:
- (git_installed.rc == 0 and git_version.stdout is version_compare('2.15', operator='lt') )

###########
# Vagrant #
###########

- name: Check if Vagrant is installed
shell: which vagrant >/dev/null 2>&1
ignore_errors: yes
register: vagrant_installed

- name: Test if the Vagrant version is >2.1
shell: vagrant --version | sed -e 's/Vagrant //g' | awk -F'[.]' '{print $1 "." $2 "." $3}'
when: vagrant_installed.rc == 0
register: vagrant_version

- name: Download Vagrant
get_url:
url: https://releases.hashicorp.com/vagrant/2.2.5/vagrant_2.2.5_x86_64.deb
dest: /tmp/vagrant_2.2.5_x86_64.deb
when:
- (vagrant_installed.rc != 0) or (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.5', operator='lt') )

- name: Remove system vagrant if necessary
apt:
name: vagrant
state: absent
when: (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.5', operator='lt') )

- name: Install Vagrant
command: dpkg -i /tmp/vagrant_2.2.5_x86_64.deb
become: yes
when:
- (vagrant_installed.rc != 0) or (vagrant_installed.rc == 0 and vagrant_version.stdout is version_compare('2.2.5', operator='lt') )

##############
# VirtualBox #
##############

- name: Check if Virtualbox is installed
shell: which virtualbox >/dev/null 2>&1
ignore_errors: yes
register: virtualbox_installed

- name: Import GPG keys
apt_key:
url: "{{ item }}"
state: present
with_items:
- https://www.virtualbox.org/download/oracle_vbox_2016.asc
- https://www.virtualbox.org/download/oracle_vbox.asc
when: virtualbox_installed.rc != 0

- name: Add Virtualbox Repository
apt_repository:
repo: deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian bionic contrib
when: virtualbox_installed.rc != 0

- name: Install Virtualbox
apt:
name: virtualbox-6.0
update_cache: yes
when: virtualbox_installed.rc != 0

0 comments on commit 8d48a2c

Please sign in to comment.