foreman_ansible 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 04ef2672d90809de50a458709449a10b393e8b4cf2eae9c1d905682822ecac82
4
- data.tar.gz: 1aadd4214a4d53962dfffc9014ae05168c8125ea7a3addc34235d29333c7c30e
2
+ SHA1:
3
+ metadata.gz: bf20c117b247b7bac631b02cdf847af6e29a5eb6
4
+ data.tar.gz: cfc11ffafe093538f48322fbd581110e34be83a4
5
5
  SHA512:
6
- metadata.gz: ae214b5e3516d85af5cb3ade922061ced9e797b39e078cfe63db3b87cc11faf817186aff3230704f2d7d501e5b0d08ccd2e042289a2ef8ae22a430ac6e09f369
7
- data.tar.gz: 3a91c4fdb49e342f20a709aaa5e9083e77af70bca95738e8aa0e2bb53441cde66e2f662351a65f2b2195b3cc365ef9793616281ecb35c17f63f0d904c541ee05
6
+ metadata.gz: 1948c441fdfe3002aee7e94abf2b0e742d0d1bd24c6a13405c72f347eb1111baf245343cd3ffb1718ae78f535b422b228964981b0b8cff2a0425c917b238f7b4
7
+ data.tar.gz: a804813c0baceb26837bb63f25d24bd57d912a74184a143ddb08127afbbc8f831c41f89dfd3f0438a8534e6b32ff3da697c213748f9d83d2bc699dc4a94fa451
data/Rakefile CHANGED
@@ -21,6 +21,8 @@ rescue StandardError => _
21
21
  puts 'Rubocop not loaded.'
22
22
  end
23
23
 
24
+ Bundler::GemHelper.install_tasks :name => 'foreman_ansible'
25
+
24
26
  task :default do
25
27
  Rake::Task['rubocop'].execute
26
28
  end
@@ -20,9 +20,19 @@ if defined? ForemanRemoteExecution
20
20
  super(template_invocation, host).merge(
21
21
  'ansible_inventory' => ::ForemanAnsible::InventoryCreator.new(
22
22
  [host], template_invocation
23
- ).to_hash.to_json
23
+ ).to_hash.to_json,
24
+ :remote_execution_command => ansible_command?(
25
+ template_invocation.template
26
+ )
24
27
  )
25
28
  end
29
+
30
+ private
31
+
32
+ def ansible_command?(template)
33
+ template.remote_execution_features.
34
+ where(:label => 'ansible_run_host').empty?
35
+ end
26
36
  end
27
37
  end
28
38
  end
@@ -2,5 +2,5 @@
2
2
  # This way other parts of Foreman can just call ForemanAnsible::VERSION
3
3
  # and detect what version the plugin is running.
4
4
  module ForemanAnsible
5
- VERSION = '2.2.0'.freeze
5
+ VERSION = '2.2.1'.freeze
6
6
  end
@@ -0,0 +1,35 @@
1
+ require 'test_plugin_helper'
2
+
3
+ # Tests for the behavior of Ansible Role, currently only validations
4
+ class AnsibleProviderTest < ActiveSupport::TestCase
5
+ describe '.proxy_command_options' do
6
+ let(:template_invocation) { FactoryBot.create(:template_invocation) }
7
+ let(:dummyhost) { FactoryBot.create(:host) }
8
+
9
+ it 'adds an ansible inventory' do
10
+ assert command_options['ansible_inventory']
11
+ end
12
+
13
+ context 'when it is not using the ansible_run_host feature' do
14
+ it 'sets enables :remote_execution_command to true' do
15
+ assert command_options[:remote_execution_command]
16
+ end
17
+ end
18
+
19
+ context 'when it is using the ansible_run_host feature' do
20
+ let(:rex_feature) do
21
+ RemoteExecutionFeature.where(:label => 'ansible_run_host').first
22
+ end
23
+
24
+ it 'has remote_execution_command false' do
25
+ template_invocation.template.remote_execution_features << rex_feature
26
+ assert_not command_options[:remote_execution_command]
27
+ end
28
+ end
29
+
30
+ def command_options
31
+ ForemanAnsible::AnsibleProvider.
32
+ proxy_command_options(template_invocation, dummyhost)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ class CommandCreatorTest < ActiveSupport::TestCase
4
+ let(:inventory_file) { 'test_inventory' }
5
+ let(:playbook_file) { 'test_palybook.yml' }
6
+ subject do
7
+ ForemanAnsibleCore::CommandCreator.new(inventory_file, playbook_file, {})
8
+ end
9
+
10
+ test 'returns a command array including the ansible-playbook command' do
11
+ assert command_parts.include?('ansible-playbook')
12
+ end
13
+
14
+ test 'the last argument is the playbook_file' do
15
+ assert command_parts.last == playbook_file
16
+ end
17
+
18
+ describe 'environment variables' do
19
+ let(:environment_variables) { subject.command.first }
20
+
21
+ test 'has a JSON_INVENTORY_FILE set' do
22
+ assert environment_variables['JSON_INVENTORY_FILE']
23
+ end
24
+
25
+ test 'has no ANSIBLE_CALLBACK_WHITELIST set by default' do
26
+ assert_not environment_variables['ANSIBLE_CALLBACK_WHITELIST']
27
+ end
28
+
29
+ test 'with a REX command it sets ANSIBLE_CALLBACK_WHITELIST to empty' do
30
+ set_command_options(:remote_execution_command, true)
31
+ assert environment_variables['ANSIBLE_CALLBACK_WHITELIST']
32
+ end
33
+ end
34
+
35
+ describe 'command options' do
36
+ it 'can have verbosity set' do
37
+ level = '3'
38
+ level_string = Array.new(level.to_i).map { 'v' }.join
39
+ set_command_options(:verbosity_level, level)
40
+ assert command_parts.any? do |part|
41
+ part == "-#{level_string}"
42
+ end
43
+ end
44
+
45
+ it 'can have a timeout set' do
46
+ timeout = '5555'
47
+ set_command_options(:timeout, timeout)
48
+ assert command_parts.include?(timeout)
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def command_parts
55
+ subject.command.flatten.map(&:to_s)
56
+ end
57
+
58
+ def set_command_options(option, value)
59
+ subject.instance_eval("@options[:#{option}] = \"#{value}\"",
60
+ __FILE__, __LINE__ - 1)
61
+ end
62
+ end
@@ -7,7 +7,7 @@ class PlaybookRunnerTest < ActiveSupport::TestCase
7
7
  test 'reads default when none provided' do
8
8
  ForemanAnsibleCore::PlaybookRunner.any_instance.stubs(:unknown_hosts).
9
9
  returns([])
10
- File.expects(:exist?).with('/etc/ansible').returns(true)
10
+ File.expects(:exist?).with(Dir.home).returns(true)
11
11
  runner = ForemanAnsibleCore::PlaybookRunner.new(nil, nil)
12
12
  assert '/etc/ansible', runner.instance_variable_get('@ansible_dir')
13
13
  end
@@ -21,7 +21,7 @@ class PlaybookRunnerTest < ActiveSupport::TestCase
21
21
 
22
22
  test 'creates temp one if not provided' do
23
23
  Dir.expects(:mktmpdir)
24
- File.expects(:exist?).with('/etc/ansible').returns(true)
24
+ File.expects(:exist?).with(Dir.home).returns(true)
25
25
  ForemanAnsibleCore::PlaybookRunner.new(nil, nil)
26
26
  end
27
27
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.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-06-14 00:00:00.000000000 Z
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -201,6 +201,7 @@ files:
201
201
  - test/test_plugin_helper.rb
202
202
  - test/unit/actions/run_ansible_job_test.rb
203
203
  - test/unit/actions/run_proxy_ansible_command_test.rb
204
+ - test/unit/ansible_provider_test.rb
204
205
  - test/unit/ansible_role_test.rb
205
206
  - test/unit/concerns/config_reports_extensions_test.rb
206
207
  - test/unit/concerns/host_managed_extensions_test.rb
@@ -208,6 +209,7 @@ files:
208
209
  - test/unit/helpers/ansible_reports_helper_test.rb
209
210
  - test/unit/host_ansible_role_test.rb
210
211
  - test/unit/hostgroup_ansible_role_test.rb
212
+ - test/unit/lib/foreman_ansible_core/command_creator_test.rb
211
213
  - test/unit/lib/foreman_ansible_core/playbook_runner_test.rb
212
214
  - test/unit/lib/foreman_ansible_core/roles_reader_test.rb
213
215
  - test/unit/lib/proxy_api/ansible_test.rb
@@ -242,40 +244,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
244
  version: '0'
243
245
  requirements: []
244
246
  rubyforge_project:
245
- rubygems_version: 2.7.3
247
+ rubygems_version: 2.6.8
246
248
  signing_key:
247
249
  specification_version: 4
248
250
  summary: Ansible integration with Foreman (theforeman.org)
249
251
  test_files:
252
+ - test/unit/host_ansible_role_test.rb
253
+ - test/unit/helpers/ansible_reports_helper_test.rb
250
254
  - test/unit/ansible_role_test.rb
255
+ - test/unit/concerns/config_reports_extensions_test.rb
256
+ - test/unit/concerns/host_managed_extensions_test.rb
257
+ - test/unit/concerns/hostgroup_extensions_test.rb
258
+ - test/unit/lib/foreman_ansible_core/command_creator_test.rb
259
+ - test/unit/lib/foreman_ansible_core/roles_reader_test.rb
260
+ - test/unit/lib/foreman_ansible_core/playbook_runner_test.rb
261
+ - test/unit/lib/proxy_api/ansible_test.rb
262
+ - test/unit/ansible_provider_test.rb
251
263
  - test/unit/hostgroup_ansible_role_test.rb
252
- - test/unit/services/api_roles_importer_test.rb
253
- - test/unit/services/fact_sparser_test.rb
254
- - test/unit/services/insights_plan_runner_test.rb
255
- - test/unit/services/structured_fact_importer_test.rb
264
+ - test/unit/services/fact_importer_test.rb
256
265
  - test/unit/services/ui_roles_importer_test.rb
257
266
  - test/unit/services/inventory_creator_test.rb
258
- - test/unit/services/fact_parser_test.rb
259
267
  - test/unit/services/roles_importer_test.rb
260
- - test/unit/services/fact_importer_test.rb
261
- - test/unit/helpers/ansible_reports_helper_test.rb
268
+ - test/unit/services/insights_plan_runner_test.rb
269
+ - test/unit/services/fact_parser_test.rb
270
+ - test/unit/services/api_roles_importer_test.rb
271
+ - test/unit/services/structured_fact_importer_test.rb
272
+ - test/unit/services/fact_sparser_test.rb
262
273
  - test/unit/actions/run_proxy_ansible_command_test.rb
263
274
  - test/unit/actions/run_ansible_job_test.rb
264
- - test/unit/lib/foreman_ansible_core/playbook_runner_test.rb
265
- - test/unit/lib/foreman_ansible_core/roles_reader_test.rb
266
- - test/unit/lib/proxy_api/ansible_test.rb
267
- - test/unit/host_ansible_role_test.rb
268
- - test/unit/concerns/host_managed_extensions_test.rb
269
- - test/unit/concerns/config_reports_extensions_test.rb
270
- - test/unit/concerns/hostgroup_extensions_test.rb
271
- - test/factories/ansible_proxy.rb
272
- - test/factories/ansible_roles.rb
273
275
  - test/test_plugin_helper.rb
274
- - test/fixtures/insights_playbook.yaml
275
- - test/fixtures/report.json
276
- - test/fixtures/sample_facts.json
277
- - test/functional/ansible_roles_controller_test.rb
276
+ - test/functional/hosts_controller_test.rb
277
+ - test/functional/api/v2/hosts_controller_test.rb
278
278
  - test/functional/api/v2/ansible_roles_controller_test.rb
279
279
  - test/functional/api/v2/hostgroups_controller_test.rb
280
- - test/functional/api/v2/hosts_controller_test.rb
281
- - test/functional/hosts_controller_test.rb
280
+ - test/functional/ansible_roles_controller_test.rb
281
+ - test/factories/ansible_roles.rb
282
+ - test/factories/ansible_proxy.rb
283
+ - test/fixtures/report.json
284
+ - test/fixtures/sample_facts.json
285
+ - test/fixtures/insights_playbook.yaml