forked from theforeman/foreman_ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible_provider.rb
82 lines (69 loc) · 2.25 KB
/
ansible_provider.rb
1
2
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true
if defined? ForemanRemoteExecution
module ForemanAnsible
# Provider for RemoteExecution that allows to run Ansible playbooks.
# Read the source of other RemoteExecution providers for more.
class AnsibleProvider < RemoteExecutionProvider
class << self
def ssh_password(host)
host_setting(host, :remote_execution_ssh_password)
end
def ssh_key_passphrase(host)
host_setting(host, :remote_execution_ssh_key_passphrase)
end
def humanized_name
'Ansible'
end
def proxy_command_options(template_invocation, host)
super(template_invocation, host).merge(
'ansible_inventory' => ::ForemanAnsible::InventoryCreator.new(
[host], template_invocation
).to_hash,
:verbosity_level => Setting[:ansible_verbosity],
:remote_execution_command => ansible_command?(
template_invocation.template
),
:name => host.name
)
end
def secrets(host)
{
'per-host' => {
host.name => {
'ansible_ssh_pass' => rex_ssh_password(host),
'ansible_become_password' => rex_effective_user_password(host)
}
}
}
end
def rex_ssh_password(host)
host_setting(host, 'remote_execution_ssh_password')
end
def rex_effective_user_password(host)
host_setting(host, 'remote_execution_effective_user_password')
end
def host_setting(host, setting)
host.params[setting.to_s] || Setting[setting]
end
def supports_effective_user?
true
end
def proxy_operation_name
'ansible-runner'
end
def required_proxy_selector_for(template)
if template.remote_execution_features.where(:label => 'ansible_run_capsule_upgrade').any?
::DefaultProxyProxySelector.new
else
super
end
end
private
def ansible_command?(template)
template.remote_execution_features.
where(:label => 'ansible_run_host').empty?
end
end
end
end
end