Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a multi_ansible provisioner #1579

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ playbooks/galaxy_collections
inventories/local_*
user_devel_env_files/
.cache
ansible_*.cfg

# Vagrant
.vagrant
Expand Down
25 changes: 21 additions & 4 deletions vagrant/lib/forklift/box_distributor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def define_vm(config, box = {})

networks = configure_networks(box.fetch('networks', []))
configure_shell(machine, box)
configure_ansible(machine, box['ansible'], box['name'])
configure_multi_ansible(machine, box)
configure_providers(machine, box, networks)
configure_synced_folders(machine, box)
configure_private_network(machine, box)
Expand Down Expand Up @@ -174,7 +174,7 @@ def configure_networks(networks)
end
end

def configure_ansible(machine, ansible, box_name)
def configure_ansible(machine, ansible, box_name, extra_vars, provisioner_name)
return unless ansible

if ansible.key?('group') && !ansible['group'].nil?
Expand All @@ -189,9 +189,9 @@ def configure_ansible(machine, ansible, box_name)
return unless (playbooks = ansible['playbook'])

[playbooks].flatten.each_with_index do |playbook, index|
machine.vm.provision("main#{index}", type: 'ansible') do |ansible_provisioner|
machine.vm.provision("#{provisioner_name}-#{index}", type: 'ansible', preserve_order: true) do |ansible_provisioner|
ansible_provisioner.playbook = playbook
ansible_provisioner.extra_vars = ansible['variables']
ansible_provisioner.extra_vars = extra_vars
ansible_provisioner.groups = @ansible_groups
ansible_provisioner.verbose = ansible['verbose'] || false
%w[config_file galaxy_role_file inventory_path].each do |key|
Expand All @@ -203,6 +203,23 @@ def configure_ansible(machine, ansible, box_name)
end
end

def configure_multi_ansible(machine, box)
ansible_provisioner_names = box.fetch('multi_ansible', ['ansible'])
return unless ansible_provisioner_names.include?('ansible')

primary_ansible = box['ansible']
return unless primary_ansible

primary_ansible_vars = primary_ansible['variables']
box_name = box['name']

ansible_provisioner_names.each do |provisioner_name|
ansible = box[provisioner_name]
extra_vars = ansible.fetch('reuse_vars', false) ? primary_ansible_vars : ansible['variables']
configure_ansible(machine, ansible, box_name, extra_vars, provisioner_name)
end
end

def configure_shell(machine, box)
return unless box.key?('shell') && !box['shell'].nil?

Expand Down