Class: ForemanAnsible::AnsibleProvider

Inherits:
RemoteExecutionProvider
  • Object
show all
Defined in:
app/models/foreman_ansible/ansible_provider.rb

Overview

Provider for RemoteExecution that allows to run Ansible playbooks. Read the source of other RemoteExecution providers for more.

Class Method Summary collapse

Class Method Details

.humanized_nameObject



17
18
19
# File 'app/models/foreman_ansible/ansible_provider.rb', line 17

def humanized_name
  'Ansible'
end

.provider_input_namespaceObject



21
22
23
# File 'app/models/foreman_ansible/ansible_provider.rb', line 21

def provider_input_namespace
  :ansible
end

.provider_inputsObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/foreman_ansible/ansible_provider.rb', line 64

def provider_inputs
  [
    ForemanRemoteExecution::ProviderInput.new(
      name: 'tags',
      label: _('Tags'),
      value: '',
      value_type: 'plain',
      description: 'Tags used for Ansible execution'
    ),
    ForemanRemoteExecution::ProviderInput.new(
      name: 'tags_flag',
      label: _('Include/Exclude Tags'),
      value: 'include',
      description: 'Option whether to include or exclude tags',
      options: "include\nexclude"
    )
  ]
end

.provider_inputs_docObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/foreman_ansible/ansible_provider.rb', line 83

def provider_inputs_doc
  opts = provider_inputs.find { |input| input.name == 'tags_flag' }.options.split("\n")
  {
    :namespace => provider_input_namespace,
    :opts => { :desc => N_('Ansible provider specific inputs') },
    :children => [
      {
        :name => :tags,
        :type => String,
        :opts => { :required => false, :desc => N_('A comma separated list of tags to use for Ansible run') }
      },
      {
        :name => :tags_flag,
        :type => opts,
        :opts => { :required => false, :desc => N_('Include\Exclude tags for Ansible run') }
      }
    ]
  }
end

.proxy_action_classObject



113
114
115
# File 'app/models/foreman_ansible/ansible_provider.rb', line 113

def proxy_action_class
  'Proxy::Ansible::TaskLauncher::Playbook::PlaybookRunnerAction'
end

.proxy_batch_sizeObject



117
118
119
120
# File 'app/models/foreman_ansible/ansible_provider.rb', line 117

def proxy_batch_size
  value = Setting['foreman_ansible_proxy_batch_size']
  value.presence && value.to_i
end

.proxy_command_options(template_invocation, host) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/foreman_ansible/ansible_provider.rb', line 25

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,
    :check_mode => host.host_param('ansible_roles_check_mode'),
    :cleanup_working_dirs => cleanup_working_dirs?(host)
  )
end

.proxy_command_provider_inputs(template_invocation) ⇒ Object



103
104
105
106
107
# File 'app/models/foreman_ansible/ansible_provider.rb', line 103

def proxy_command_provider_inputs(template_invocation)
  tags = template_invocation.provider_input_values.find_by(:name => 'tags')&.value || ''
  tags_flag = template_invocation.provider_input_values.find_by(:name => 'tags_flag')&.value || ''
  { :tags => tags, :tags_flag => tags_flag }
end

.proxy_operation_nameObject



109
110
111
# File 'app/models/foreman_ansible/ansible_provider.rb', line 109

def proxy_operation_name
  'ansible-runner'
end

.rex_effective_user_password(host) ⇒ Object



56
57
58
# File 'app/models/foreman_ansible/ansible_provider.rb', line 56

def rex_effective_user_password(host)
  host_setting(host, 'remote_execution_effective_user_password')
end

.rex_ssh_password(host) ⇒ Object



52
53
54
# File 'app/models/foreman_ansible/ansible_provider.rb', line 52

def rex_ssh_password(host)
  host_setting(host, 'remote_execution_ssh_password')
end

.secrets(host) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/foreman_ansible/ansible_provider.rb', line 40

def secrets(host)
  {
    :key_passphrase => Setting[:remote_execution_ssh_key_passphrase],
    'per-host' => {
      host.name => {
        'ansible_password' => rex_ssh_password(host),
        'ansible_become_password' => rex_effective_user_password(host)
      }
    }
  }
end

.ssh_key_passphrase(host) ⇒ Object



13
14
15
# File 'app/models/foreman_ansible/ansible_provider.rb', line 13

def ssh_key_passphrase(host)
  host_setting(host, :remote_execution_ssh_key_passphrase)
end

.ssh_password(host) ⇒ Object



9
10
11
# File 'app/models/foreman_ansible/ansible_provider.rb', line 9

def ssh_password(host)
  host_setting(host, :remote_execution_ssh_password)
end

.supports_effective_user?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/foreman_ansible/ansible_provider.rb', line 60

def supports_effective_user?
  true
end