Vagrant: multiple playbooks for ansible provisioner
Asked Answered
R

2

8

Is it possible / valid to run more than one playbooks for a vagrant ansible provisioner in the following form:

 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
Riptide answered 3/4, 2017 at 11:18 Comment(0)
J
16

no it will not be valid

If you want to run 2 playbook, you would need to run the ansible provisioner twice, this can be done like

 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
Jamima answered 3/4, 2017 at 11:52 Comment(0)
W
1

You can also use a role instead of the playbook and the role contains pointers to multiple playbooks which are defined in the roles subdirectories. For example playbook.yml contains

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

Both BaseOS and users exist in the roles subdirectory and will be executed in sequence when playbook.yml is called.

Winfrid answered 5/6, 2019 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.