Skip to content

Commit

Permalink
Support custom ansible.cfg
Browse files Browse the repository at this point in the history
move role_path generated parameter to an environment variable
  • Loading branch information
neillturner committed Oct 27, 2015
1 parent d9e8128 commit a39380d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
kitchen-ansible (0.0.28)
kitchen-ansible (0.0.29)
librarian-ansible
test-kitchen

Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen-ansible/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Kitchen
module Ansible
VERSION = "0.0.28"
VERSION = "0.0.29"
end
end
43 changes: 26 additions & 17 deletions lib/kitchen/provisioner/ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ def run_command
if http_proxy
cmd = "HTTP_PROXY=#{http_proxy} #{cmd}"
end
if ansible_roles_path
cmd = "ANSIBLE_ROLES_PATH=#{ansible_roles_path} #{cmd}"
end

result = [
cmd,
ansible_inventory_flag,
Expand Down Expand Up @@ -666,6 +670,21 @@ def export_http_proxy
cmd
end

def ansible_roles_path
roles_paths = []
roles_paths << File.join(config[:root_path], 'roles') unless config[:roles_path].nil?
additional_files.each do |additional_file|
roles_paths << File.join(config[:root_path], File.basename(additional_file))
end
if roles_paths.empty?
info('No roles have been set.')
nil
else
debug("Setting roles_path inside VM to #{ roles_paths.join(':') }")
roles_paths.join(':')
end
end

def prepare_roles
info('Preparing roles')
debug("Using roles from #{roles}")
Expand All @@ -683,27 +702,17 @@ def prepare_roles
FileUtils.cp_r(Dir.glob("#{roles}/*"), File.join(tmp_roles_dir, role_name))
end

# /etc/ansible/ansible.cfg should contain
# roles_path = /tmp/kitchen/roles
# copy ansible.cfg if found in root of repo
def prepare_ansible_cfg
info('Preparing ansible.cfg file')
ansible_config_file = "#{File.join(sandbox_path, 'ansible.cfg')}"

roles_paths = []
roles_paths << File.join(config[:root_path], 'roles') unless config[:roles_path].nil?
additional_files.each do |additional_file|
roles_paths << File.join(config[:root_path], File.basename(additional_file))
end

if roles_paths.empty?
info('No roles have been set. empty ansible.cfg generated')
File.open(ansible_config_file, "wb") do |file|
file.write("#no roles path specified\n")
end
if File.exist?('ansible.cfg')
info("Found existing ansible.cfg")
FileUtils.cp_r('ansible.cfg', ansible_config_file)
else
debug("Setting roles_path inside VM to #{ roles_paths.join(':') }")
File.open( ansible_config_file, "wb") do |file|
file.write("[defaults]\nroles_path = #{ roles_paths.join(':') }\n")
info('Empty ansible.cfg generated')
File.open(ansible_config_file, "wb") do |file|
file.write("#no config parameters\n")
end
end
end
Expand Down

0 comments on commit a39380d

Please sign in to comment.