Vagrant:ansible provisioner的多个剧本

时间:2017-04-03 11:18:31

标签: vagrant ansible provisioning vagrantfile vagrant-provision

以下列形式为流浪的ansible供应商运行多个剧本是否可行/有效:

 config.vm.define "repo", primary: true do |d|
    d.vm.hostname = "some.hostname"
    # Create a private network, which allows host-only access to the machine
    # using a specific IP.
    d.vm.network :private_network, ip: "10.10.2.90"
    d.vm.provision 'ansible' do |ansible|
      ansible.config_file = 'ansible/ansible.cfg'
      ansible.playbook = 'ansible/playbook1.yml'
      ansible.playbook = 'ansible/playbook2.yml'
      ansible.sudo = true
      ansible.inventory_path = 'ansible/inventory/site'
      ansible.host_key_checking = false
    end
  end

2 个答案:

答案 0 :(得分:6)

不,它无效

如果你想运行2个剧本,你需要运行两次ansible配置器,这可以像

那样完成
 config.vm.define "repo", primary: true do |d|
    d.vm.hostname = "some.hostname"
    # Create a private network, which allows host-only access to the machine
    # using a specific IP.
    d.vm.network :private_network, ip: "10.10.2.90"

    # First playbook
    d.vm.provision  "playbook1", type:'ansible' do |ansible|
      ansible.config_file = 'ansible/ansible.cfg'
      ansible.playbook = 'ansible/playbook1.yml'
      ansible.sudo = true
      ansible.inventory_path = 'ansible/inventory/site'
      ansible.host_key_checking = false
    end

    # Second playbook
    d.vm.provision  "playbook2", type:'ansible' do |ansible|
      ansible.config_file = 'ansible/ansible.cfg'
      ansible.playbook = 'ansible/playbook2.yml'
      ansible.sudo = true
      ansible.inventory_path = 'ansible/inventory/site'
      ansible.host_key_checking = false
    end
  end

答案 1 :(得分:0)

您还可以使用角色代替剧本,并且该角色包含指向在角色子目录中定义的多个剧本的指针。例如playbook.yml包含

---
- name: BaseOS configuration
  hosts: all
  become: yes
  roles:
    - baseos
    - users

BaseOS和用户都存在于role子目录中,并在调用playbook.yml时按顺序执行。