Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant: multiple playbooks for ansible provisioner

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
like image 569
pkaramol Avatar asked Apr 03 '17 11:04

pkaramol


2 Answers

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
like image 90
Frederic Henri Avatar answered Oct 08 '22 22:10

Frederic Henri


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.

like image 24
cpe111 Avatar answered Oct 08 '22 22:10

cpe111