Vagrant没有提供shell脚本

时间:2017-09-29 19:58:03

标签: shell vagrant vagrantfile vagrant-provision

我有一个Vagrant文件,看起来像这样

# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'json'
require 'yaml'

VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path(File.dirname(__FILE__))

homesteadYamlPath = confDir + "/Homestead.yaml"
homesteadJsonPath = confDir + "/Homestead.json"
afterScriptPath = confDir + "/after.sh"
aliasesPath = confDir + "/aliases"

require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')

Vagrant.require_version '>= 1.9.0'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.box_check_update = false
    if File.exist? aliasesPath then
        config.vm.provision "file", source: aliasesPath, destination: "/tmp/bash_aliases"
        config.vm.provision "shell" do |s|
            s.inline = "awk '{ sub(\"\r$\", \"\"); print }' /tmp/bash_aliases > /home/vagrant/.bash_aliases"
        end
    end

    if File.exist? homesteadYamlPath then
        settings = YAML::load(File.read(homesteadYamlPath))
    elsif File.exist? homesteadJsonPath then
        settings = JSON.parse(File.read(homesteadJsonPath))
    else
        abort "Homestead settings file not found in #{confDir}"
    end

    Homestead.configure(config, settings)

    if File.exist? afterScriptPath then
        config.vm.provision "shell", path: afterScriptPath, privileged: false, env:  {VM_VAR:ENV['HOST_VAR']}
    end

    if defined? VagrantPlugins::HostsUpdater
        config.hostsupdater.aliases = settings['sites'].map { |site| site['map'] }
    end
end

它是laravel homestead Vagrantfile,但在if File.exist? afterScriptPath then内部进行了更改,我刚刚添加了env

但问题是,当我尝试运行vagrant provision时,它会运行所有的宅基地脚本,但不会运行我的脚本。我的after.sh(或afterScriptPath变量)我已经把简单的shell脚本放在了

#!/bin/sh
sudo -s
echo 'installing some extra software'
echo $VM_VAR
touch /usr/local/extra_homestead_software_installed

测试我会得到的内容,但在配置时不会echo,并且不会创建extra_homestead_software_installed文件。

我在这里错过了

0 个答案:

没有答案