From 290d65c049bd9211d1b594f8cdaa78f4b0556839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 22 Jan 2014 10:31:01 +0100 Subject: [PATCH] vagrant: script to upgrade chef in advance --- Vagrantfile | 12 +++++++++++- script/fix_stdin_error.sh | 10 ++++++++++ script/upgrade_chef.sh | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 script/fix_stdin_error.sh create mode 100644 script/upgrade_chef.sh diff --git a/Vagrantfile b/Vagrantfile index 71153e8..1cd2f45 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -42,7 +42,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| boxes.each do |box| config.vm.define box[:name] do |node| node.vm.provider :virtualbox do |vb| - vb.gui = true + # access via tty => user: vagrant, password: vagrant + #vb.gui = true + # 1. adapter: NAT to allow vagrant setup the machine # 2. adapter: for internal network between nodes vb.customize ["modifyvm", :id, @@ -56,6 +58,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| node.vm.hostname = box[:name] + # Update Chef in VM to specific version before running chef provisioner + config.vm.provision :shell do |shell| + shell.path = "script/upgrade_chef.sh" + # target version + shell.args = "11.8.2" + end + config.vm.provision(:shell){ |shell| shell.path = "script/fix_stdin_error.sh" } + config.vm.provision :chef_solo do |chef| chef_default.call(chef) chef.add_role box[:role].to_s diff --git a/script/fix_stdin_error.sh b/script/fix_stdin_error.sh new file mode 100644 index 0000000..0102a29 --- /dev/null +++ b/script/fix_stdin_error.sh @@ -0,0 +1,10 @@ +# If last line is `mesg n`, replace with conditional. +if [ "`tail -1 /root/.profile`" = "mesg n" ]; then + echo 'Patching basebox to prevent future `stdin: is not a tty` errors...' + sed -i '$d' /root/.profile + cat << 'EOH' >> /root/.profile + if `tty -s`; then + mesg n + fi +EOH +fi diff --git a/script/upgrade_chef.sh b/script/upgrade_chef.sh new file mode 100644 index 0000000..e79c828 --- /dev/null +++ b/script/upgrade_chef.sh @@ -0,0 +1,8 @@ +gem=/opt/chef/embedded/bin/gem +chef=/opt/chef/bin/chef-client + +if [ "`$chef -v | awk '{print $NF}'`" != "$1" ]; then + echo "Upgrading Chef to $1..."; + $gem uninstall chef --all --ignore-dependencies --executables + $gem install chef -v $1 --no-rdoc --no-ri +fi