其他客人起床后,在特定客人上的流浪命令



我有以下vagrantfile:

Vagrant.configure(VAGRANT_API_VERSION) do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 1024
    vb.cpus = 2
  end
  config.vm.define :master do |master_config|
    master_config.vm.box = "centos/7"
    master_config.vm.host_name = 'saltmaster.local'
    master_config.vm.network "private_network", ip: "172.16.10.10"
    master_config.vm.synced_folder ".", "/vagrant", disabled: true
    master_config.vm.synced_folder "states", "/vagrant/states", type: "virtualbox"
    master_config.vm.synced_folder "pillar", "/vagrant/pillar", type: "virtualbox"
    master_config.vm.provision :salt do |salt|
      salt.master_config = "etc/master"
      salt.install_type = "git"
      salt.install_args = "v2016.11.7"
      salt.no_minion = true
      salt.install_master = true
      salt.verbose = true
      salt.colorize = true
      salt.bootstrap_options = "-P -c /tmp"
    end
  end
  config.vm.define :minion1 do |minion_config|
    minion_config.vm.box = "centos/7"
    minion_config.vm.host_name = 'saltminion1.local'
    minion_config.vm.network "private_network", ip: "172.16.10.11"
    minion_config.vm.synced_folder ".", "/vagrant", disabled: true
    minion_config.vm.provision :salt do |salt|
      salt.minion_config = "etc/minion1"
      salt.install_type = "git"
      salt.install_args = "v2016.11.7"
      salt.verbose = true
      salt.colorize = true
      salt.bootstrap_options = "-P -c /tmp"
    end
  end
  config.vm.define :minion2 do |minion_config|
    minion_config.vm.box = "centos/7"
    minion_config.vm.host_name = 'saltminion2.local'
    minion_config.vm.network "private_network", ip: "172.16.10.12"
    minion_config.vm.synced_folder ".", "/vagrant", disabled: true
    minion_config.vm.provision :salt do |salt|
      salt.minion_config = "etc/minion2"
      salt.install_type = "git"
      salt.install_args = "v2016.11.7"
      salt.verbose = true
      salt.colorize = true
      salt.bootstrap_options = "-P -c /tmp"
    end
  end
end

现在,在所有机器启动并运行后,我想使用master_config.vm.provision "shell", inline: "salt '*' state.apply"在盐主上执行命令。

但是,问题是,一旦Vagrant完成的供应Minion2,它将无法再访问Master_Config机器了。我认为应该有一种执行该命令的方法,而不必执行vagrant ssh master -c stalt '*' state.apply。我不想在主机上使用命令。由于某些与网络相关的配置和状态。

有人可以帮我吗?

...继续从评论中继续进行示例。

您可以使用流浪触发插件。如文档中所述:

从0.5.0版开始,触发器也可以作为Provisioner

运行
  • 您可以针对特定实例(请参阅https://github.com/emyl/vagrant-triggers#options)

因此,文件末尾的以下内容应起作用:

  config.vm.provision "trigger", :vm => "minion_config" do |trigger|
    trigger.fire do
      run "script"
    end
  end

相关内容

  • 没有找到相关文章

最新更新