【问题标题】:Vagrant: multiple playbooks for ansible provisionerVagrant:ansible Provisioner 的多个剧本
【发布时间】:2017-04-03 11:18:30
【问题描述】:

是否可以/有效地以下列形式为 vagrant ansible provisioner 运行多个剧本:

 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

【问题讨论】:

    标签: vagrant ansible provisioning vagrantfile vagrant-provision


    【解决方案1】:

    不,这将是无效的

    如果你想运行 2 个 playbook,你需要运行 ansible provisioner 两次,这可以像这样完成

     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
    

    【讨论】:

      【解决方案2】:

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

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

      BaseOS和users都存在于roles子目录下,调用playbook.yml时会依次执行。

      【讨论】:

        猜你喜欢
        • 2017-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多