Top Level Namespace
Defined Under Namespace
Modules: Kitchen
Classes: PrintInventory
Constant Summary
collapse
- TEMP_INV_DIR =
'.kitchen/ansiblepush'.freeze
- TEMP_GROUP_FILE =
"#{TEMP_INV_DIR}/ansiblepush_groups_inventory.yml".freeze
Instance Method Summary
collapse
Instance Method Details
#chef_installation_script(chef_url, omnibus_download_dir) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/kitchen-ansible/chef_installation.rb', line 2
def chef_installation_script(chef_url, omnibus_download_dir)
<<-INSTALL
if [ ! -d "/opt/chef" ]; then
echo "-----> Installing Chef Omnibus needed by busser and serverspec"
echo " You can use https://github.com/neillturner/kitchen-verifier-serverspec to avoid installing chef."
mkdir -p #{omnibus_download_dir}
if [ ! -x #{omnibus_download_dir}/install.sh ]; then
do_download #{chef_url} #{omnibus_download_dir}/install.sh
fi
sudo sh #{omnibus_download_dir}/install.sh -d #{omnibus_download_dir}
echo "-----> End Installing Chef Omnibus"
fi
INSTALL
end
|
#generate_instance_inventory(name, host, mygroup, instance_connection_option, ansible_connection) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/kitchen-ansible/util_inventory.rb', line 11
def generate_instance_inventory(name, host, mygroup, instance_connection_option, ansible_connection)
unless instance_connection_option.nil?
port = instance_connection_option[:port]
keys = instance_connection_option[:keys]
user = instance_connection_option[:user]
pass = instance_connection_option[:pass]
end
temp_hash = {}
temp_hash['ansible_ssh_host'] = host
temp_hash['ansible_ssh_port'] = port if port
temp_hash['ansible_ssh_private_key_file'] = keys[0] if keys
temp_hash['ansible_ssh_user'] = user if user
temp_hash['ansible_ssh_pass'] = pass if pass
temp_hash['mygroup'] = mygroup if mygroup
if ansible_connection == 'winrm'
temp_hash['ansible_winrm_server_cert_validation'] = 'ignore'
temp_hash['ansible_winrm_transport'] = 'ssl'
end
{ name => temp_hash }
end
|
#idempotency_test ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/kitchen-ansible/idempotancy.rb', line 3
def idempotency_test
info('*************** idempotency test ***************')
file_path = "/tmp/kitchen_ansible_callback/#{SecureRandom.uuid}.changes"
exec_ansible_command(
command_env.merge(
'ANSIBLE_CALLBACK_PLUGINS' => "#{File.dirname(__FILE__)}/../../callback/",
'ANSIBLE_CALLBACK_WHITELIST' => 'changes',
'PLUGIN_CHANGES_FILE' => file_path
), command, 'ansible-playbook'
)
debug("idempotency file #{file_path}")
if File.file?(file_path)
task = 0
info('idempotency test [Failed]')
File.open(file_path, 'r') do |f|
f.each_line do |line|
task += 1
info(" #{task}> #{line.strip}")
end
end
raise "idempotency test Failed. Number of non idempotent tasks: #{task}" if conf[:fail_non_idempotent]
info('Warning idempotency test [failed]')
else
info('idempotency test [passed]')
end
end
|
#write_var_to_yaml(yaml_file, hash_var) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/kitchen-ansible/util_inventory.rb', line 4
def write_var_to_yaml(yaml_file, hash_var)
Dir.mkdir TEMP_INV_DIR unless File.exist?(TEMP_INV_DIR)
File.open(yaml_file, 'w') do |file|
file.write hash_var.to_yaml
end
end
|