foreman_ansible_core 2.0.2 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c69f61506d641e18d27a22a32514cdb6221174dd
|
4
|
+
data.tar.gz: 9afe8696e6723ad9ab66adf416b457e8fa9dfec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c40433c92f4c4f3d617562cad983a0b116b8240830bb14d6d641aa17187845dc1649a3e4da75f81af6485b66efffc69f8fc2a431212e938989c10fa54604ef3b
|
7
|
+
data.tar.gz: 7080dd69b55873db5305ba237dc7d5e7331cecd1e23c2969125eaf553e115573663205bf0fa46b5331686661330150c44a7dec6fc5278b5f9070498f87e83c5e
|
data/lib/foreman_ansible_core.rb
CHANGED
@@ -1,28 +1,39 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
begin
|
2
|
+
require 'foreman_tasks_core'
|
3
|
+
require 'foreman_remote_execution_core'
|
4
|
+
# rubocop:disable Lint/HandleExceptions
|
5
|
+
rescue LoadError
|
6
|
+
# These gems are not available in a proxy SCLed context
|
7
|
+
# puts 'Running Foreman Ansible Core in non-SCL context'
|
8
|
+
end
|
9
|
+
# rubocop:enable Lint/HandleExceptions
|
3
10
|
|
4
11
|
# Core actions for Foreman Ansible, used by both Foreman and Foreman proxy
|
5
12
|
# This comprises running playbooks for the moment
|
6
13
|
module ForemanAnsibleCore
|
7
|
-
extend ForemanTasksCore::SettingsLoader
|
8
|
-
register_settings(:ansible, :ansible_dir => '/etc/ansible',
|
9
|
-
:working_dir => nil)
|
10
14
|
require 'foreman_ansible_core/exception'
|
15
|
+
require 'foreman_ansible_core/roles_reader'
|
16
|
+
require 'foreman_ansible_core/version'
|
11
17
|
|
12
|
-
if ForemanTasksCore
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
18
|
+
if defined? ForemanTasksCore
|
19
|
+
extend ForemanTasksCore::SettingsLoader
|
20
|
+
register_settings(:ansible, :ansible_dir => Dir.home,
|
21
|
+
:working_dir => nil)
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
)
|
23
|
+
if ForemanTasksCore.dynflow_present?
|
24
|
+
require 'foreman_tasks_core/runner'
|
25
|
+
require 'foreman_ansible_core/playbook_runner'
|
26
|
+
require 'foreman_ansible_core/actions'
|
27
|
+
end
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
if defined? ForemanTasksCore
|
31
|
+
require 'foreman_remote_execution_core/actions'
|
32
|
+
require 'foreman_ansible_core/remote_execution_core/ansible_runner'
|
33
|
+
require 'foreman_ansible_core/remote_execution_core/settings_override'
|
34
|
+
ForemanRemoteExecutionCore::Actions::RunScript.send(
|
35
|
+
:prepend,
|
36
|
+
ForemanAnsibleCore::RemoteExecutionCore::SettingsOverride
|
37
|
+
)
|
38
|
+
end
|
28
39
|
end
|
@@ -1,23 +1,34 @@
|
|
1
1
|
module ForemanAnsibleCore
|
2
2
|
# Creates the actual command to be passed to foreman_tasks_core to run
|
3
3
|
class CommandCreator
|
4
|
-
attr_reader :command
|
5
|
-
|
6
4
|
def initialize(inventory_file, playbook_file, options = {})
|
7
5
|
@options = options
|
8
|
-
@
|
9
|
-
@
|
10
|
-
|
11
|
-
|
6
|
+
@playbook_file = playbook_file
|
7
|
+
@inventory_file = inventory_file
|
8
|
+
command
|
9
|
+
end
|
10
|
+
|
11
|
+
def command
|
12
|
+
parts = [environment_variables]
|
13
|
+
parts << 'ansible-playbook'
|
14
|
+
parts.concat(command_options)
|
15
|
+
parts << @playbook_file
|
16
|
+
parts
|
12
17
|
end
|
13
18
|
|
14
19
|
private
|
15
20
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def environment_variables
|
22
|
+
defaults = { 'JSON_INVENTORY_FILE' => @inventory_file }
|
23
|
+
defaults['ANSIBLE_CALLBACK_WHITELIST'] = '' if rex_command?
|
24
|
+
defaults
|
25
|
+
end
|
26
|
+
|
27
|
+
def command_options
|
28
|
+
opts = ['-i', json_inventory_script]
|
29
|
+
opts.concat([setup_verbosity]) if verbose?
|
30
|
+
opts.concat(['-T', @options[:timeout]]) unless @options[:timeout].nil?
|
31
|
+
opts
|
21
32
|
end
|
22
33
|
|
23
34
|
def json_inventory_script
|
@@ -40,5 +51,9 @@ module ForemanAnsibleCore
|
|
40
51
|
verbosity_level.to_i > 0
|
41
52
|
# rubocop:enable Rails/Present
|
42
53
|
end
|
54
|
+
|
55
|
+
def rex_command?
|
56
|
+
@options[:remote_execution_command]
|
57
|
+
end
|
43
58
|
end
|
44
59
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'foreman_tasks_core/runner/command_runner'
|
2
2
|
require_relative 'command_creator'
|
3
3
|
require 'tmpdir'
|
4
|
+
require 'net/ssh'
|
4
5
|
|
5
6
|
module ForemanAnsibleCore
|
6
7
|
# Implements ForemanTasksCore::Runner::Base interface for running
|
@@ -11,6 +12,9 @@ module ForemanAnsibleCore
|
|
11
12
|
def initialize(inventory, playbook, options = {})
|
12
13
|
super
|
13
14
|
@inventory = inventory
|
15
|
+
unknown_hosts.each do |host|
|
16
|
+
add_to_known_hosts(host)
|
17
|
+
end
|
14
18
|
@playbook = playbook
|
15
19
|
@options = options
|
16
20
|
initialize_dirs
|
@@ -94,5 +98,22 @@ module ForemanAnsibleCore
|
|
94
98
|
!ansible_dir.nil? && File.exist?(ansible_dir)
|
95
99
|
@ansible_dir = ansible_dir
|
96
100
|
end
|
101
|
+
|
102
|
+
def unknown_hosts
|
103
|
+
JSON.parse(@inventory)['all']['hosts'].select do |host|
|
104
|
+
Net::SSH::KnownHosts.search_for(host).empty?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_to_known_hosts(host)
|
109
|
+
logger.warn("[foreman_ansible] - Host #{host} not found in known_hosts")
|
110
|
+
Net::SSH::Transport::Session.new(host).host_keys.each do |host_key|
|
111
|
+
Net::SSH::KnownHosts.add(host, host_key)
|
112
|
+
end
|
113
|
+
logger.warn("[foreman_ansible] - Added host key #{host} to known_hosts")
|
114
|
+
rescue StandardError => e
|
115
|
+
logger.error('[foreman_ansible] - Failed to save host key for '\
|
116
|
+
"#{host}: #{e}")
|
117
|
+
end
|
97
118
|
end
|
98
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_ansible_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Lobato Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: net-ssh
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
55
69
|
description: |2
|
56
70
|
Ansible integration with Foreman - core parts for dealing with Ansible concepts,
|
57
71
|
usable by foreman_ansible or smart_proxy_ansible to delegate the execution.
|
@@ -92,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
106
|
version: '0'
|
93
107
|
requirements: []
|
94
108
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.6.
|
109
|
+
rubygems_version: 2.6.8
|
96
110
|
signing_key:
|
97
111
|
specification_version: 4
|
98
112
|
summary: 'Ansible integration with Foreman (theforeman.org): core bits'
|