使用SaltStack grain文件和Vagrant

时间:2015-05-06 09:44:50

标签: vagrant vagrantfile salt-stack vagrant-plugin

我想使用minion.d/*.conf来配置流浪汉机器。 这是我的Vagrant配置:

Vagrant.configure("2") do |config|
  ## Choose your base box
  config.vm.box = "precise64"

  ## For masterless, mount your salt file root
  config.vm.synced_folder "salt/roots/", "/srv/salt/"

  ## Use all the defaults:
  config.vm.provision :salt do |salt|

    salt.minion_config = "salt/minion"
    salt.run_highstate = true
    salt.grains_config = "salt/minion.d/vagrant.conf"

  end
end

配置Vagrant机器后,我在呈现SLS文件时出错,因为minion.d/*.conf文件未被复制到客户机下:

/etc/salt/minion.d/

我应该在Vagrant配置中进行同步配置吗?

3 个答案:

答案 0 :(得分:3)

您刚刚尝试将同步文件夹挂载到/etc/salt/grains吗?

## For masterless, mount your salt file root
config.vm.synced_folder "salt/roots/", "/srv/salt/"
config.vm.synced_folder "salt/grains.d/", "/etc/salt/grains.d/"

答案 1 :(得分:3)

@ Utah_Dave的解决方案可以正常工作,或者您可以执行以下操作(这是我运行它的方式)。

<强>文件系统

function get_url_content_type( $url ) {

    $header = get_headers( $url, 1 );

    if ( isset( $header['Content-Type'] ) ) {

        return $header['Content-Type'];
    }
}

<强> Vagrantfile

/dev
  Vagrantfile
  salt-minion.conf
  salt/
    top.sls
    my-awesome-state/init.sls
  pillar/
    top.sls
    my-awesome-pillar.sls

<强>盐minion.conf

Vagrant.configure("2") do |config|
  config.vm.box = "mafro/jessie64-au-salt"

  # salt config directory & shared dir in /tmp
  config.vm.synced_folder ".", "/srv/salt"

  # setup the salt-minion
  config.vm.provision :salt do |salt|
    salt.minion_config = "salt-minion.conf"
  end
end

答案 2 :(得分:1)

Vagrant对 salt.grains_config 的实施不会像您预期的那样将文件复制到 /etc/salt/minion.d 文件夹。相反,它将文件复制到 / etc / salt / grains

要让salt-minion读取这个新的 grain 文件,您只需将以下内容添加到您的minion配置中:

的/ etc /盐/仆从

include:
  - /etc/salt/grains