foreman_ansible 1.5.2 → 2.0.0
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 +4 -4
- data/Rakefile +1 -1
- data/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +6 -21
- data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +5 -18
- data/app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb +12 -5
- data/app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb +20 -16
- data/app/controllers/foreman_ansible/concerns/job_invocation_helper.rb +17 -0
- data/app/helpers/foreman_ansible/ansible_plugin_helper.rb +1 -5
- data/app/helpers/foreman_ansible/ansible_reports_helper.rb +2 -1
- data/app/helpers/foreman_ansible/hosts_helper_extensions.rb +19 -18
- data/app/lib/actions/foreman_ansible/helpers/host_common.rb +1 -5
- data/app/models/ansible_role.rb +5 -0
- data/app/models/concerns/foreman_ansible/has_many_ansible_roles.rb +1 -3
- data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +9 -0
- data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +0 -4
- data/app/models/foreman_ansible/ansible_provider.rb +24 -0
- data/app/models/setting/ansible.rb +4 -1
- data/app/services/foreman_ansible/fact_parser.rb +4 -2
- data/app/services/foreman_ansible/inventory_creator.rb +7 -2
- data/app/services/foreman_ansible/proxy_selector.rb +6 -0
- data/app/services/foreman_ansible/ui_roles_importer.rb +2 -0
- data/app/views/ansible_roles/index.html.erb +1 -2
- data/app/views/foreman_ansible/ansible_roles/_hostgroup_ansible_roles_button.erb +8 -7
- data/app/views/foreman_ansible/job_templates/ansible_roles.erb +17 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20160705082036_create_ansible_role.rb +1 -1
- data/db/migrate/20160706074540_create_join_table_hosts_ansible_roles.rb +1 -1
- data/db/migrate/20160707195442_create_host_ansible_roles.rb +1 -1
- data/db/migrate/20160729094457_add_columns_to_ansible_role.rb +1 -1
- data/db/migrate/20160802153302_create_join_table_hostgroup_ansible_roles.rb +2 -1
- data/db/migrate/20160805094233_add_primary_key_hostgroup_ansible_roles.rb +1 -1
- data/db/migrate/20161122154057_automatically_set_role_timestamps.rb +1 -1
- data/db/seeds.d/75_job_templates.rb +20 -0
- data/lib/foreman_ansible/engine.rb +11 -53
- data/lib/foreman_ansible/register.rb +52 -0
- data/lib/foreman_ansible/remote_execution.rb +22 -0
- data/lib/foreman_ansible/version.rb +1 -1
- data/test/factories/ansible_proxy.rb +1 -1
- data/test/factories/ansible_roles.rb +1 -1
- data/test/functional/ansible_roles_controller_test.rb +4 -2
- data/test/functional/api/v2/ansible_roles_controller_test.rb +5 -3
- data/test/functional/api/v2/hostgroups_controller_test.rb +17 -25
- data/test/functional/api/v2/hosts_controller_test.rb +16 -24
- data/test/functional/hosts_controller_test.rb +33 -29
- data/test/test_plugin_helper.rb +12 -2
- data/test/unit/actions/run_ansible_job_test.rb +0 -0
- data/test/unit/actions/run_proxy_ansible_command_test.rb +0 -0
- data/test/unit/concerns/host_managed_extensions_test.rb +7 -7
- data/test/unit/concerns/hostgroup_extensions_test.rb +6 -6
- data/test/unit/helpers/foreman_ansible/ansible_reports_helper_test.rb +2 -2
- data/test/unit/host_ansible_role_test.rb +2 -2
- data/test/unit/hostgroup_ansible_role_test.rb +2 -2
- data/test/unit/lib/foreman_ansible_core/roles_reader_test.rb +4 -5
- data/test/unit/services/fact_importer_test.rb +3 -5
- data/test/unit/services/fact_parser_test.rb +0 -2
- data/test/unit/services/fact_sparser_test.rb +0 -2
- data/test/unit/services/inventory_creator_test.rb +1 -1
- data/test/unit/services/proxy_selector_test.rb +4 -4
- data/test/unit/services/roles_importer_test.rb +2 -2
- data/test/unit/services/structured_fact_importer_test.rb +1 -1
- data/test/unit/services/ui_roles_importer_test.rb +1 -1
- metadata +44 -31
- data/app/lib/actions/foreman_ansible/play_host_roles.rb +0 -42
- data/app/lib/actions/foreman_ansible/play_hostgroup_roles.rb +0 -56
- data/app/lib/actions/foreman_ansible/play_hosts_roles.rb +0 -26
- data/test/fixtures/ansible_permissions.yml +0 -11
- data/test/support/fixture_support.rb +0 -29
- data/test/support/foreman_tasks/task.rb +0 -48
- data/test/support/foreman_test_helper_additions.rb +0 -22
@@ -1,42 +0,0 @@
|
|
1
|
-
module Actions
|
2
|
-
module ForemanAnsible
|
3
|
-
# Action that initiates the playbook run for roles assigned to
|
4
|
-
# the host. It does that either locally or via a proxy when available.
|
5
|
-
class PlayHostRoles < Actions::EntryAction
|
6
|
-
include ::Actions::Helpers::WithContinuousOutput
|
7
|
-
include ::Actions::Helpers::WithDelegatedAction
|
8
|
-
include Helpers::PlayRolesDescription
|
9
|
-
include Helpers::HostCommon
|
10
|
-
|
11
|
-
def plan(host, proxy_selector = ::ForemanAnsible::ProxySelector.new,
|
12
|
-
options = {})
|
13
|
-
proxy = find_host_and_proxy(host, proxy_selector)
|
14
|
-
role_names = host.all_ansible_roles.map(&:name)
|
15
|
-
inventory_creator = ::ForemanAnsible::InventoryCreator.new([host])
|
16
|
-
playbook_creator = ::ForemanAnsible::PlaybookCreator.new(role_names)
|
17
|
-
plan_delegated_action(proxy,
|
18
|
-
::ForemanAnsibleCore::Actions::RunPlaybook,
|
19
|
-
:inventory => inventory_creator.to_hash.to_json,
|
20
|
-
:playbook => playbook_creator.roles_playbook,
|
21
|
-
:options => find_options.merge(options))
|
22
|
-
plan_self
|
23
|
-
end
|
24
|
-
|
25
|
-
def humanized_input
|
26
|
-
format(_('on host %{name} through %{proxy}'),
|
27
|
-
:name => input.fetch(:host, {})[:name],
|
28
|
-
:proxy => running_proxy_name)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def find_host_and_proxy(host, proxy_selector)
|
34
|
-
proxy = proxy_selector.determine_proxy(host)
|
35
|
-
input[:host] = { :id => host.id,
|
36
|
-
:name => host.fqdn,
|
37
|
-
:proxy_used => proxy.try(:name) || :not_defined }
|
38
|
-
proxy
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Actions
|
2
|
-
module ForemanAnsible
|
3
|
-
# Action that initiates the playbook run for roles assigned to
|
4
|
-
# the hostgroup. It does that either locally or via a proxy when available.
|
5
|
-
class PlayHostgroupRoles < Actions::EntryAction
|
6
|
-
include ::Actions::Helpers::WithContinuousOutput
|
7
|
-
include ::Actions::Helpers::WithDelegatedAction
|
8
|
-
include Helpers::PlayRolesDescription
|
9
|
-
include Helpers::HostCommon
|
10
|
-
|
11
|
-
def plan(hostgroup, proxy_selector = ::ForemanAnsible::ProxySelector.new,
|
12
|
-
options = {})
|
13
|
-
proxy = find_hostgroup_and_proxy(hostgroup, proxy_selector)
|
14
|
-
inventory_creator = ::ForemanAnsible::
|
15
|
-
InventoryCreator.new(hostgroup.hosts)
|
16
|
-
playbook_creator = ::ForemanAnsible::
|
17
|
-
PlaybookCreator.new(hostgroup_ansible_roles(hostgroup))
|
18
|
-
plan_delegated_action(proxy, ::ForemanAnsibleCore::Actions::RunPlaybook,
|
19
|
-
:inventory => inventory_creator.to_hash.to_json,
|
20
|
-
:playbook => playbook_creator.roles_playbook,
|
21
|
-
:options => find_options.merge(options))
|
22
|
-
plan_self
|
23
|
-
end
|
24
|
-
|
25
|
-
def humanized_input
|
26
|
-
format(_('on host group %{name} through proxy %{proxy}'),
|
27
|
-
:name => input.fetch(:hostgroup, {})[:name],
|
28
|
-
:proxy => running_proxy_name)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def hostgroup_ansible_roles(hostgroup)
|
34
|
-
role_names = []
|
35
|
-
hostgroup.hostgroup_ansible_roles.each do |ansible_role|
|
36
|
-
role_names.append(ansible_role.ansible_role_name)
|
37
|
-
end
|
38
|
-
role_names
|
39
|
-
end
|
40
|
-
|
41
|
-
def hostgroup_contains_hosts(hostgroup)
|
42
|
-
return unless hostgroup.hosts.empty?
|
43
|
-
raise ::Foreman::Exception.new(N_('host group is empty'))
|
44
|
-
end
|
45
|
-
|
46
|
-
def find_hostgroup_and_proxy(hostgroup, proxy_selector)
|
47
|
-
hostgroup_contains_hosts(hostgroup)
|
48
|
-
proxy = proxy_selector.determine_proxy(hostgroup.hosts[0])
|
49
|
-
input[:hostgroup] = { :id => hostgroup.id,
|
50
|
-
:name => hostgroup.name,
|
51
|
-
:proxy_used => proxy.try(:name) || :not_defined }
|
52
|
-
proxy
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Actions
|
2
|
-
module ForemanAnsible
|
3
|
-
# Bulk action for running ansible roles
|
4
|
-
class PlayHostsRoles < Actions::ActionWithSubPlans
|
5
|
-
def plan(hosts)
|
6
|
-
plan_self(:host_ids => hosts.map(&:id))
|
7
|
-
end
|
8
|
-
|
9
|
-
def create_sub_plans
|
10
|
-
proxy_selector = ::ForemanAnsible::ProxySelector.new
|
11
|
-
input[:host_ids].map do |host_id|
|
12
|
-
host = Host.find(host_id)
|
13
|
-
trigger(PlayHostRoles, host, proxy_selector)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def rescue_strategy
|
18
|
-
::Dynflow::Action::Rescue::Fail
|
19
|
-
end
|
20
|
-
|
21
|
-
def humanized_name
|
22
|
-
_('Bulk play Ansible roles')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
---
|
2
|
-
view_ansible_roles:
|
3
|
-
name: view_ansible_roles
|
4
|
-
resource_type: AnsibleRole
|
5
|
-
created_at: "2013-12-04 08:41:04.321867"
|
6
|
-
updated_at: "2013-12-04 08:41:04.321867"
|
7
|
-
destroy_ansible_roles:
|
8
|
-
name: destroy_ansible_roles
|
9
|
-
resource_type: AnsibleRole
|
10
|
-
created_at: "2013-12-04 08:41:04.321867"
|
11
|
-
updated_at: "2013-12-04 08:41:04.321867"
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module ForemanAnsible
|
2
|
-
# Allow to add fixtures to plugins
|
3
|
-
module PluginFixtures
|
4
|
-
FIXTURE_MAPPING = {
|
5
|
-
:ansible_permissions => :permissions
|
6
|
-
}.freeze
|
7
|
-
|
8
|
-
def self.add_fixtures(new_fixture_path)
|
9
|
-
FileUtils.cp(
|
10
|
-
Dir.glob(Rails.root.join('test', 'fixtures', '*')),
|
11
|
-
new_fixture_path
|
12
|
-
)
|
13
|
-
copy_plugin_fixtures new_fixture_path
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.copy_plugin_fixtures(new_fixture_path)
|
17
|
-
FIXTURE_MAPPING.each do |key, value|
|
18
|
-
fixture_path = "#{ForemanAnsible::Engine.root}/test/fixtures/#{key}.yml"
|
19
|
-
break unless File.exist?(fixture_path)
|
20
|
-
File.open("#{new_fixture_path}/#{value}.yml", 'a') do |file|
|
21
|
-
File.open(fixture_path, 'r').each do |line|
|
22
|
-
next if line =~ /---/
|
23
|
-
file.write line
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Support
|
2
|
-
module ForemanTasks
|
3
|
-
# Stubbing for foreman tasks
|
4
|
-
module Task
|
5
|
-
def stub_tasks!
|
6
|
-
@controller.stubs(:sync_task).returns(build_task_stub)
|
7
|
-
@controller.stubs(:async_task).returns(build_task_stub)
|
8
|
-
end
|
9
|
-
|
10
|
-
def build_task_stub
|
11
|
-
task_attrs = [:id, :label, :pending, :username, :started_at, :ended_at,
|
12
|
-
:state, :result, :progress, :input, :humanized,
|
13
|
-
:cli_example].inject({}) { |a, e| a.update e => nil }
|
14
|
-
task_attrs[:output] = {}
|
15
|
-
|
16
|
-
stub('task', task_attrs).mimic!(::ForemanTasks::Task)
|
17
|
-
end
|
18
|
-
|
19
|
-
def assert_async_task(expected_action_class, *args_expected)
|
20
|
-
assert_foreman_task(true, expected_action_class, *args_expected)
|
21
|
-
end
|
22
|
-
|
23
|
-
def assert_sync_task(expected_action_class, *args_expected)
|
24
|
-
assert_foreman_task(false, expected_action_class, *args_expected)
|
25
|
-
end
|
26
|
-
|
27
|
-
def assert_foreman_task(async, expected_action_class, *args_expected)
|
28
|
-
block ||= block_from_args(args_expected)
|
29
|
-
method = async ? :async_task : :sync_task
|
30
|
-
task_stub = build_task_stub
|
31
|
-
@controller.
|
32
|
-
expects(method).
|
33
|
-
with do |action_class, *args|
|
34
|
-
expected_action_class == action_class && block.call(*args)
|
35
|
-
end.
|
36
|
-
returns(task_stub)
|
37
|
-
task_stub
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def block_from_args(args_expected)
|
43
|
-
->(*_) { true } if args_expected.empty?
|
44
|
-
->(*args) { args == args_expected }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require "#{ForemanAnsible::Engine.root}/test/support/fixture_support"
|
2
|
-
# loads the permissions for foreman_ansible and makes them available in tests
|
3
|
-
module AnsiblePermissionTestCase
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
extend ActiveRecord::TestFixtures
|
8
|
-
|
9
|
-
new_fixture_path = Dir.mktmpdir('ansible_fixtures')
|
10
|
-
self.fixture_path = new_fixture_path
|
11
|
-
ForemanAnsible::PluginFixtures.add_fixtures(new_fixture_path)
|
12
|
-
fixtures(:all)
|
13
|
-
load_fixtures(ActiveRecord::Base)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module ActiveSupport
|
18
|
-
#:nodoc
|
19
|
-
class TestCase
|
20
|
-
include AnsiblePermissionTestCase
|
21
|
-
end
|
22
|
-
end
|