From 22c84f61221cf22823a4a885b41708fc3a5420a8 Mon Sep 17 00:00:00 2001 From: Jan Beilicke Date: Wed, 25 Nov 2020 22:39:37 +0000 Subject: [PATCH] Adds a simple way to provision the VM from within the VM by letting Vagrant install Ansible and run it locally. --- Vagrantfile | 23 ++++++++++++++++---- provisioning/{inventory => inventory.sample} | 0 provisioning/playbook.yml | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) rename provisioning/{inventory => inventory.sample} (100%) diff --git a/Vagrantfile b/Vagrantfile index f9d2546..21577d2 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -38,12 +38,12 @@ Vagrant.configure(2) do |config| #vbox.customize ["storageattach", :id, "--storagectl", "SCSI", "--port", 1, "--nonrotational", "on"] # Set to true, if you intent to use a GUI - vbox.gui = false + vbox.gui = true end config.vm.define "jbdev" do |dev| dev.vm.hostname = "jbdev.local" - + # If you have installed the Vagrant::Hostsupdate plugin, you can add additional domains # that should be mapped to the VM. #dev.hostsupdater.aliases = ["jenkins.jbdev.local", "grafana.jbdev.local"] @@ -54,11 +54,26 @@ Vagrant.configure(2) do |config| # https://www.virtualbox.org/manual/ch06.html#network_nat_service dev.vm.network :private_network, ip: "192.168.6.65" - dev.vm.provision :ansible do |ansible| + # Provision the VM from the Vagrant host. + # The host has to have Ansible installed and will connect to the VM via SSH + # dev.vm.provision :ansible do |ansible| + # #ansible.verbose = "vvv" + # ansible.compatibility_mode = "2.0" + # ansible.playbook = "provisioning/playbook.yml" + # ansible.inventory_path = "provisioning/inventory" + # ansible.become = true + # end + + # Provision by running Ansible from within the VM. + # Vagrant will try to install Ansible automatically using pip + # Advantage: Ansible doesn't have to be installed on the Vagrant host + dev.vm.provision "ansible_local" do |ansible| #ansible.verbose = "vvv" ansible.compatibility_mode = "2.0" + ansible.install_mode = "pip" + ansible.version = "2.10.3" ansible.playbook = "provisioning/playbook.yml" - ansible.inventory_path = "provisioning/inventory" + #ansible.inventory_path = "provisioning/inventory" ansible.become = true end end diff --git a/provisioning/inventory b/provisioning/inventory.sample similarity index 100% rename from provisioning/inventory rename to provisioning/inventory.sample diff --git a/provisioning/playbook.yml b/provisioning/playbook.yml index 04a8172..d71f855 100644 --- a/provisioning/playbook.yml +++ b/provisioning/playbook.yml @@ -1,4 +1,4 @@ -- hosts: jbdev +- hosts: all gather_facts: yes become: yes