如何将ansible变量传递给vagrant

How to pass ansible variables into vagrant

假设我有一个剧本,我通常 运行 如下:

ansible-playbook -i hosts -e "var1=val1" \
    -e "hosts=all" \
    -e "devops_dir=$DEVOPS_PATH" \
    -e "cname=something.gooten.com" \
    -v playbook.yml

我想在启动 Vagrantfile 时使用这个 运行--

  #
  # Run Ansible from the Vagrant Host
  #
  config.ssh.insert_key = false
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
    ansible.verbose = "v"
  end

如何将 -e 变量添加到 Vagrantfile 中以便它们也被调用?

你必须使用extra_vars

ansible.extra_vars = {
  var1: val1,
  hosts: all,
  devops_dir: $DEVOPS_PATH,
  cname: something.gooten.com
}