From 37447621b983317e70d476f99a2f65f3e3fe7623 Mon Sep 17 00:00:00 2001 From: Jon Benson Date: Sun, 10 Jun 2018 16:52:31 -0400 Subject: [PATCH] F update vagrantfile (#46) * Update Vagrantfile * Update output * Fix output * Update Vagrantfile * Don't run tests --- .../dev/vagrant-local/Vagrantfile | 78 +++++++++---------- 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/operations/provision-vault/dev/vagrant-local/Vagrantfile b/operations/provision-vault/dev/vagrant-local/Vagrantfile index 05b8175b..b6f439f9 100644 --- a/operations/provision-vault/dev/vagrant-local/Vagrantfile +++ b/operations/provision-vault/dev/vagrant-local/Vagrantfile @@ -3,13 +3,13 @@ # Networking private_ip = ENV['PRIVATE_IP'] || "192.168.50.152" -consul_host_port = ENV['CONSUL_HOST_PORT'] || 8500 -vault_host_port = ENV['VAULT_HOST_PORT'] || 8200 # Base box selection base_box = ENV['BASE_BOX'] || "bento/ubuntu-16.04" # Consul variables +consul_install = ["true", "1"].include?((ENV['CONSUL_INSTALL'] || true).to_s.downcase) +consul_host_port = ENV['CONSUL_HOST_PORT'] || 8500 consul_version = ENV['CONSUL_VERSION'] || "1.0.6" consul_ent_url = ENV['CONSUL_ENT_URL'] consul_group = "consul" @@ -18,6 +18,7 @@ consul_comment = "Consul" consul_home = "/srv/consul" # Vault variables +vault_host_port = ENV['VAULT_HOST_PORT'] || 8200 vault_version = ENV['VAULT_VERSION'] || "0.10.0" vault_ent_url = ENV['VAULT_ENT_URL'] vault_group = "vault" @@ -25,18 +26,12 @@ vault_user = "vault" vault_comment = "Vault" vault_home = "/srv/vault" -# Tests & cleanup -run_tests = ENV['RUN_TESTS'] -cleanup = ENV['CLEANUP'] - Vagrant.configure("2") do |config| # Use vagrant insecure public key, comment this out to restrict access config.ssh.insert_key = false # Setup networking config.vm.network :private_network, ip: private_ip - config.vm.network :forwarded_port, guest: 8500, host: consul_host_port, auto_correct: true - config.vm.network :forwarded_port, guest: 8200, host: vault_host_port, auto_correct: true config.vm.network "private_network", type: "dhcp" # Use base_box set at the top of this file @@ -46,25 +41,33 @@ Vagrant.configure("2") do |config| # Bootstrap the vm config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/base.sh | bash" - # Setup Consul user - config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-user.sh | bash", - env: { - "GROUP" => consul_group, - "USER" => consul_user, - "COMMENT" => consul_comment, - "HOME" => consul_home, - } - - # Install Consul - config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul.sh | bash", - env: { - "VERSION" => consul_version, - "URL" => consul_ent_url, - "USER" => consul_user, - "GROUP" => consul_group, - } + if (consul_install) + # Forward Consul port + config.vm.network :forwarded_port, guest: 8500, host: consul_host_port, auto_correct: true + + # Setup Consul user + config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-user.sh | bash", + env: { + "GROUP" => consul_group, + "USER" => consul_user, + "COMMENT" => consul_comment, + "HOME" => consul_home, + } + + # Install Consul + config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul.sh | bash", + env: { + "VERSION" => consul_version, + "URL" => consul_ent_url, + "USER" => consul_user, + "GROUP" => consul_group, + } + + config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul-systemd.sh | bash" + end - config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/consul/scripts/install-consul-systemd.sh | bash" + # Forward Vault port + config.vm.network :forwarded_port, guest: 8200, host: vault_host_port, auto_correct: true # Setup Vault user config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-user.sh | bash", @@ -86,19 +89,6 @@ Vagrant.configure("2") do |config| config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/vault/scripts/install-vault-systemd.sh | bash" - # Setup tests - config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/setup-testing.sh | bash" - - # Run tests if `RUN_TESTS` env var is provided - if (run_tests) - config.vm.provision "shell", inline: "cd /tmp && rake vault:spec" - end - - # Cleanup if `CLEANUP` env var is provided - if (cleanup) - config.vm.provision "shell", inline: "curl https://raw.githubusercontent.com/hashicorp/guides-configuration/master/shared/scripts/cleanup.sh | bash" - end - # Increase memory for Parallels Desktop config.vm.provider "parallels" do |p, o| p.memory = "1024" @@ -123,9 +113,11 @@ To SSH into a Vault host, run the below command. $ vagrant ssh -You can interact with Vault using any of the CLI (https://www.vaultproject.io/docs/commands/index.html) or API (https://www.vaultproject.io/api/index.html) commands. +You can interact with Vault using any of the CLI (https://www.vaultproject.io/docs/commands/index.html) +or API (https://www.vaultproject.io/api/index.html) commands. - # The Root token for your Vault -dev instance is set to `root` and placed in /srv/vault/.vault-token, the `VAULT_TOKEN` environment variable has already been set for you + # The Root token for your Vault -dev instance is set to `root` and placed in /srv/vault/.vault-token, + # the `VAULT_TOKEN` environment variable has already been set for you $ echo $VAULT_TOKEN $ sudo cat /srv/vault/.vault-token @@ -137,8 +129,8 @@ You can interact with Vault using any of the CLI (https://www.vaultproject.io/do $ curl -H \"X-Vault-Token: $VAULT_TOKEN\" -X POST -d '{\"data\": {\"bar\":\"baz\"}}' http://127.0.0.1:8200/v1/secret/data/api | jq '.' $ curl -H \"X-Vault-Token: $VAULT_TOKEN\" http://127.0.0.1:8200/v1/secret/data/api | jq '.' -Visit the Consul UI: http://#{private_ip}:#{consul_host_port}/ -Visit the Vault UI: http://#{private_ip}:#{vault_host_port}/ +Visit the Vault UI: http://#{private_ip}:#{vault_host_port} +#{consul_install ? 'Visit the Consul UI: http://'+ private_ip + ':' + consul_host_port.to_s : ''} Don't forget to tear your VM down after.