foreman_ansible 6.0.2 → 6.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ansible_roles_controller.rb +12 -8
- data/app/controllers/ansible_variables_controller.rb +4 -0
- data/app/controllers/api/v2/ansible_inventories_controller.rb +2 -2
- data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
- data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
- data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
- data/app/helpers/foreman_ansible/ansible_reports_helper.rb +42 -56
- data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
- data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
- data/app/jobs/sync_roles_and_variables.rb +20 -0
- data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +10 -7
- data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +19 -4
- data/app/models/foreman_ansible/ansible_provider.rb +52 -2
- data/app/models/host_ansible_role.rb +1 -0
- data/app/models/hostgroup_ansible_role.rb +1 -0
- data/app/models/setting/ansible.rb +9 -0
- data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
- data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
- data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
- data/app/services/foreman_ansible/fact_parser.rb +21 -1
- data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
- data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
- data/app/services/foreman_ansible/inventory_creator.rb +3 -7
- data/app/services/foreman_ansible/operating_system_parser.rb +8 -2
- data/app/services/foreman_ansible/roles_importer.rb +3 -2
- data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
- data/app/services/foreman_ansible/variables_importer.rb +36 -1
- data/app/views/ansible_roles/import.html.erb +10 -50
- data/app/views/ansible_variables/index.html.erb +1 -2
- data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
- data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +8 -17
- data/app/views/foreman_ansible/config_reports/_ansible.html.erb +24 -8
- data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
- data/app/views/foreman_ansible/job_templates/ansible_roles_-_ansible_default.erb +4 -0
- data/app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb +1 -1
- data/app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb +2 -3
- data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
- data/config/routes.rb +5 -4
- data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
- data/db/seeds.d/100_common_parameters.rb +7 -0
- data/db/seeds.d/90_notification_blueprints.rb +19 -1
- data/lib/foreman_ansible/engine.rb +1 -1
- data/lib/foreman_ansible/register.rb +7 -5
- data/lib/foreman_ansible/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ca/foreman_ansible.po +1 -1
- data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/cs_CZ/foreman_ansible.po +1 -1
- data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/de/foreman_ansible.po +1 -1
- data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en/foreman_ansible.po +1 -1
- data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en_GB/foreman_ansible.po +1 -1
- data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/es/foreman_ansible.po +1 -1
- data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/fr/foreman_ansible.po +1 -1
- data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/gl/foreman_ansible.po +1 -1
- data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/it/foreman_ansible.po +1 -1
- data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ja/foreman_ansible.po +1 -1
- data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ko/foreman_ansible.po +1 -1
- data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/nl_NL/foreman_ansible.po +1 -1
- data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pl/foreman_ansible.po +1 -1
- data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pt_BR/foreman_ansible.po +1 -1
- data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ru/foreman_ansible.po +1 -1
- data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/sv_SE/foreman_ansible.po +1 -1
- data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_CN/foreman_ansible.po +1 -1
- data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_TW/foreman_ansible.po +1 -1
- data/package.json +13 -42
- data/test/factories/ansible_roles.rb +12 -0
- data/test/factories/host_ansible_enhancements.rb +23 -0
- data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
- data/test/functional/ansible_variables_controller_test.rb +0 -15
- data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
- data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
- data/test/functional/api/v2/hosts_controller_test.rb +9 -8
- data/test/functional/hosts_controller_test.rb +10 -6
- data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
- data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
- data/test/unit/helpers/ansible_reports_helper_test.rb +4 -30
- data/test/unit/host_ansible_role_test.rb +2 -1
- data/test/unit/hostgroup_ansible_role_test.rb +2 -1
- data/test/unit/ignore_roles_test.rb +43 -0
- data/test/unit/import_roles_and_variables.rb +60 -0
- data/test/unit/services/ansible_variables_importer_test.rb +13 -0
- data/test/unit/services/api_roles_importer_test.rb +22 -5
- data/test/unit/services/fact_parser_test.rb +16 -0
- data/test/unit/services/inventory_creator_test.rb +15 -7
- data/test/unit/services/ui_roles_importer_test.rb +2 -2
- data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.js +35 -0
- data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.scss +6 -0
- data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.test.js +14 -0
- data/webpack/components/AnsibleHostDetail/index.js +6 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
- data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +25 -27
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +20 -14
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
- data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +6 -4
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +1 -9
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +3 -16
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -8
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
- data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +1 -1
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +1 -1
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +4 -1
- data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +1 -1
- data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsiblePermissionDenied.test.js.snap +2 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AvailableRolesList.test.js.snap +5 -0
- data/webpack/components/AnsibleRolesSwitcher/index.js +4 -8
- data/webpack/global_index.js +12 -0
- data/webpack/index.js +6 -13
- metadata +54 -30
- data/app/views/ansible_variables/import.html.erb +0 -56
- data/test/unit/lib/foreman_ansible_core/ansible_runner_test.rb +0 -51
- data/test/unit/lib/foreman_ansible_core/command_creator_test.rb +0 -64
- data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +0 -110
- data/webpack/__mocks__/foremanReact/common/I18n.js +0 -1
- data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +0 -2
- data/webpack/__mocks__/foremanReact/components/common/EmptyState.js +0 -5
- data/webpack/test_setup.js +0 -12
@@ -0,0 +1,20 @@
|
|
1
|
+
class SyncRolesAndVariables < ::ApplicationJob
|
2
|
+
queue_as :default
|
3
|
+
|
4
|
+
def perform(changed, proxy)
|
5
|
+
roles_importer = ForemanAnsible::UiRolesImporter.new(proxy)
|
6
|
+
variables_importer = ForemanAnsible::VariablesImporter.new(proxy)
|
7
|
+
roles_importer.finish_import(changed)
|
8
|
+
variables_importer.import_variables_roles(changed) if changed['new'] || changed['old']
|
9
|
+
task = ForemanTasks::Task.where(:external_id => @provider_job_id)[0]
|
10
|
+
ForemanAnsible::ImportRolesAndVariablesSuccessNotification.deliver!(task)
|
11
|
+
rescue StandardError => e
|
12
|
+
task = ForemanTasks::Task.where(:external_id => @provider_job_id)[0]
|
13
|
+
notification = ForemanAnsible::ImportRolesAndVariablesErrorNotification.new(e, task)
|
14
|
+
notification.deliver!
|
15
|
+
end
|
16
|
+
|
17
|
+
def humanized_name
|
18
|
+
_('Import roles And Variables')
|
19
|
+
end
|
20
|
+
end
|
@@ -8,9 +8,12 @@ module ForemanAnsible
|
|
8
8
|
base.instance_eval do
|
9
9
|
include ::ForemanAnsible::Concerns::JobInvocationHelper
|
10
10
|
|
11
|
-
has_many :host_ansible_roles, :foreign_key => :host_id
|
12
|
-
|
13
|
-
|
11
|
+
has_many :host_ansible_roles, -> { order('host_ansible_roles.position ASC') }, :foreign_key => :host_id
|
12
|
+
accepts_nested_attributes_for :host_ansible_roles, :allow_destroy => true
|
13
|
+
has_many :ansible_roles,
|
14
|
+
-> { order('host_ansible_roles.position ASC') },
|
15
|
+
:through => :host_ansible_roles,
|
16
|
+
:dependent => :destroy
|
14
17
|
scoped_search :relation => :ansible_roles, :on => :name,
|
15
18
|
:complete_value => true, :rename => :ansible_role,
|
16
19
|
:only_explicit => true
|
@@ -47,7 +50,7 @@ module ForemanAnsible
|
|
47
50
|
end
|
48
51
|
|
49
52
|
def all_ansible_roles
|
50
|
-
(
|
53
|
+
(inherited_ansible_roles + ansible_roles).uniq
|
51
54
|
end
|
52
55
|
|
53
56
|
# Class methods we may need to override or add
|
@@ -68,9 +71,9 @@ end
|
|
68
71
|
module Host
|
69
72
|
class Managed
|
70
73
|
apipie :class do
|
71
|
-
property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host, both its own and inherited'
|
72
|
-
property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles assigned to the host'
|
73
|
-
property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns
|
74
|
+
property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host, both its own and inherited from the host group and its parents'
|
75
|
+
property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles directly assigned to the host'
|
76
|
+
property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns only ansible roles assigned to the host\'s host group and its parents'
|
74
77
|
end
|
75
78
|
# Methods to be allowed in any template with safemode enabled
|
76
79
|
class Jail < Safemode::Jail
|
@@ -7,8 +7,11 @@ module ForemanAnsible
|
|
7
7
|
|
8
8
|
included do
|
9
9
|
has_many :hostgroup_ansible_roles, :foreign_key => :hostgroup_id
|
10
|
-
has_many :ansible_roles,
|
11
|
-
|
10
|
+
has_many :ansible_roles,
|
11
|
+
-> { order('hostgroup_ansible_roles.position ASC') },
|
12
|
+
:through => :hostgroup_ansible_roles,
|
13
|
+
:dependent => :destroy
|
14
|
+
accepts_nested_attributes_for :hostgroup_ansible_roles, :allow_destroy => true
|
12
15
|
audit_associations :ansible_roles
|
13
16
|
|
14
17
|
def inherited_ansible_roles
|
@@ -24,15 +27,27 @@ module ForemanAnsible
|
|
24
27
|
end
|
25
28
|
|
26
29
|
def host_ansible_roles
|
27
|
-
hosts.
|
30
|
+
hosts.includes(:host_ansible_roles).flat_map(&:ansible_roles)
|
28
31
|
end
|
29
32
|
|
30
33
|
# includes also roles of all assigned hosts, useful to determine if
|
31
34
|
# at least one host in this hostgroup has some ansible role assigned
|
32
35
|
# either directly or through hostgroup
|
33
36
|
def all_ansible_roles
|
34
|
-
(
|
37
|
+
(inherited_ansible_roles + ansible_roles + host_ansible_roles).uniq
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
42
|
+
|
43
|
+
class Hostgroup
|
44
|
+
apipie :class do
|
45
|
+
property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host group, both its own and inherited from parent host groups'
|
46
|
+
property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles directly assigned to the host group'
|
47
|
+
property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns only the inherited ansible roles assigned to the host group\'s parents'
|
48
|
+
end
|
49
|
+
# Methods to be allowed in any template with safemode enabled
|
50
|
+
class Jail < Safemode::Jail
|
51
|
+
allow :all_ansible_roles, :ansible_roles, :inherited_ansible_roles
|
52
|
+
end
|
53
|
+
end
|
@@ -18,6 +18,10 @@ if defined? ForemanRemoteExecution
|
|
18
18
|
'Ansible'
|
19
19
|
end
|
20
20
|
|
21
|
+
def provider_input_namespace
|
22
|
+
:ansible
|
23
|
+
end
|
24
|
+
|
21
25
|
def proxy_command_options(template_invocation, host)
|
22
26
|
super(template_invocation, host).merge(
|
23
27
|
'ansible_inventory' => ::ForemanAnsible::InventoryCreator.new(
|
@@ -27,7 +31,8 @@ if defined? ForemanRemoteExecution
|
|
27
31
|
:remote_execution_command => ansible_command?(
|
28
32
|
template_invocation.template
|
29
33
|
),
|
30
|
-
:name => host.name
|
34
|
+
:name => host.name,
|
35
|
+
:check_mode => host.host_param('ansible_roles_check_mode')
|
31
36
|
)
|
32
37
|
end
|
33
38
|
|
@@ -58,12 +63,57 @@ if defined? ForemanRemoteExecution
|
|
58
63
|
true
|
59
64
|
end
|
60
65
|
|
66
|
+
def provider_inputs
|
67
|
+
[
|
68
|
+
ForemanRemoteExecution::ProviderInput.new(
|
69
|
+
name: 'tags',
|
70
|
+
label: _('Tags'),
|
71
|
+
value: '',
|
72
|
+
value_type: 'plain',
|
73
|
+
description: 'Tags used for Ansible execution'
|
74
|
+
),
|
75
|
+
ForemanRemoteExecution::ProviderInput.new(
|
76
|
+
name: 'tags_flag',
|
77
|
+
label: _('Include/Exclude Tags'),
|
78
|
+
value: 'include',
|
79
|
+
description: 'Option whether to include or exclude tags',
|
80
|
+
options: "include\nexclude"
|
81
|
+
)
|
82
|
+
]
|
83
|
+
end
|
84
|
+
|
85
|
+
def provider_inputs_doc
|
86
|
+
opts = provider_inputs.find { |input| input.name == 'tags_flag' }.options.split("\n")
|
87
|
+
{
|
88
|
+
:namespace => provider_input_namespace,
|
89
|
+
:opts => { :desc => N_('Ansible provider specific inputs') },
|
90
|
+
:children => [
|
91
|
+
{
|
92
|
+
:name => :tags,
|
93
|
+
:type => Array,
|
94
|
+
:opts => { :required => false, :desc => N_('A comma separated list of tags to use for Ansible run') }
|
95
|
+
},
|
96
|
+
{
|
97
|
+
:name => :tags_flag,
|
98
|
+
:type => opts,
|
99
|
+
:opts => { :required => false, :desc => N_('Include\Exclude tags for Ansible run') }
|
100
|
+
}
|
101
|
+
]
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def proxy_command_provider_inputs(template_invocation)
|
106
|
+
tags = template_invocation.provider_input_values.find_by(:name => 'tags')&.value || ''
|
107
|
+
tags_flag = template_invocation.provider_input_values.find_by(:name => 'tags_flag')&.value || ''
|
108
|
+
{ :tags => tags, :tags_flag => tags_flag }
|
109
|
+
end
|
110
|
+
|
61
111
|
def proxy_operation_name
|
62
112
|
'ansible-runner'
|
63
113
|
end
|
64
114
|
|
65
115
|
def proxy_action_class
|
66
|
-
'
|
116
|
+
'Proxy::Ansible::TaskLauncher::Playbook::PlaybookRunnerAction'
|
67
117
|
end
|
68
118
|
|
69
119
|
private
|
@@ -3,6 +3,7 @@
|
|
3
3
|
class Setting
|
4
4
|
# Provide settings related with Ansible
|
5
5
|
class Ansible < ::Setting
|
6
|
+
::Setting::BLANK_ATTRS.concat %w[ansible_roles_to_ignore]
|
6
7
|
class << self
|
7
8
|
# It would be more disadvantages than advantages to split up
|
8
9
|
# default_settings into multiple methods, this way it's already very
|
@@ -80,6 +81,14 @@ class Setting
|
|
80
81
|
'with Ansible inventory'),
|
81
82
|
'Ansible - Ansible Inventory',
|
82
83
|
N_('Default Ansible inventory report template')
|
84
|
+
),
|
85
|
+
set(
|
86
|
+
'ansible_roles_to_ignore',
|
87
|
+
N_('Those roles will be excluded when importing roles from smart proxy, '\
|
88
|
+
'The expected input is comma separated values and you can use * wildcard metacharacters'\
|
89
|
+
'For example: foo*, *b*,*bar'),
|
90
|
+
[],
|
91
|
+
N_('Ansible roles to ignore')
|
83
92
|
)
|
84
93
|
]
|
85
94
|
end
|
@@ -18,6 +18,10 @@ module ForemanAnsible
|
|
18
18
|
partial_hostname_match(hostname)
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.authorized_smart_proxy_features
|
22
|
+
super + ['Ansible']
|
23
|
+
end
|
24
|
+
|
21
25
|
def partial_hostname_match(hostname)
|
22
26
|
return @host unless @host.new_record?
|
23
27
|
hosts = Host.where(Host.arel_table[:name].matches("#{hostname}.%"))
|
@@ -5,7 +5,21 @@ module ForemanAnsible
|
|
5
5
|
# sets the origin of the report to 'Ansible'
|
6
6
|
class AnsibleReportScanner
|
7
7
|
class << self
|
8
|
-
def add_reporter_data(
|
8
|
+
def add_reporter_data(_report, raw)
|
9
|
+
check_mode_message = raw['check_mode'] ? 'check_mode_enabled' : 'check_mode_disabled'
|
10
|
+
check_mode_log = {
|
11
|
+
'log': {
|
12
|
+
'sources': {
|
13
|
+
'source': 'check_mode'
|
14
|
+
},
|
15
|
+
'messages': {
|
16
|
+
'message': check_mode_message
|
17
|
+
},
|
18
|
+
'level': 'info'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
raw['logs'].insert(0, check_mode_log.deep_stringify_keys)
|
22
|
+
end
|
9
23
|
|
10
24
|
def identify_origin(raw)
|
11
25
|
'Ansible' if ansible_report?(raw)
|
@@ -3,15 +3,31 @@
|
|
3
3
|
module ForemanAnsible
|
4
4
|
# imports Ansible roles through API
|
5
5
|
class ApiRolesImporter < RolesImporter
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
include ::ForemanAnsible::AnsibleRolesDataPreparations
|
7
|
+
|
8
|
+
def import!(role_names)
|
9
|
+
@roles_importer = ForemanAnsible::UiRolesImporter.new(@ansible_proxy)
|
10
|
+
@variables_importer = ForemanAnsible::VariablesImporter.new(@ansible_proxy)
|
11
|
+
params = { 'changed' => {} }
|
12
|
+
roles = prepare_ansible_import_rows(@roles_importer.import!, @variables_importer, false)
|
13
|
+
roles.each do |role|
|
14
|
+
if role_names.include? role[:name]
|
15
|
+
params['changed'][role[:kind]] ||= {}
|
16
|
+
params['changed'][role[:kind]][role[:name]] = { 'id' => role[:id], 'name' => role[:name] }
|
11
17
|
end
|
12
18
|
end
|
13
|
-
|
14
|
-
|
19
|
+
params
|
20
|
+
end
|
21
|
+
|
22
|
+
def confirm_import(params)
|
23
|
+
@roles_importer.finish_import(params['changed'])
|
24
|
+
@variables_importer.import_variables_roles(params['changed']) if params['changed']['new'] || params['changed']['old']
|
25
|
+
end
|
26
|
+
|
27
|
+
def confirm_sync(params)
|
28
|
+
job = SyncRolesAndVariables.perform_later(params['changed'], @ansible_proxy)
|
29
|
+
task = ForemanTasks::Task.find_by(external_id: job.provider_job_id)
|
30
|
+
task
|
15
31
|
end
|
16
32
|
|
17
33
|
def obsolete!
|
@@ -19,9 +35,5 @@ module ForemanAnsible
|
|
19
35
|
obsolete_roles.map(&:destroy)
|
20
36
|
obsolete_roles
|
21
37
|
end
|
22
|
-
|
23
|
-
def fetch!
|
24
|
-
fetch_role_names
|
25
|
-
end
|
26
38
|
end
|
27
39
|
end
|
@@ -72,6 +72,22 @@ module ForemanAnsible
|
|
72
72
|
Time.zone.now.to_i - facts['ansible_uptime_seconds'].to_i
|
73
73
|
end
|
74
74
|
|
75
|
+
def virtual
|
76
|
+
facts['ansible_virtualization_role'] == 'guest'
|
77
|
+
end
|
78
|
+
|
79
|
+
def ram
|
80
|
+
facts['ansible_memtotal_mb'].to_i
|
81
|
+
end
|
82
|
+
|
83
|
+
def sockets
|
84
|
+
facts['ansible_processor_count'].to_i
|
85
|
+
end
|
86
|
+
|
87
|
+
def cores
|
88
|
+
facts['ansible_processor_cores'].to_i
|
89
|
+
end
|
90
|
+
|
75
91
|
private
|
76
92
|
|
77
93
|
def ansible_interfaces
|
@@ -85,7 +101,11 @@ module ForemanAnsible
|
|
85
101
|
|
86
102
|
def ip_from_interface(interface)
|
87
103
|
return if facts[:"ansible_#{interface}"]['ipv4'].blank?
|
88
|
-
facts[:"ansible_#{interface}"]['ipv4']
|
104
|
+
if facts[:"ansible_#{interface}"]['ipv4'].is_a?(Array)
|
105
|
+
facts[:"ansible_#{interface}"]['ipv4'][0]['address']
|
106
|
+
else
|
107
|
+
facts[:"ansible_#{interface}"]['ipv4']['address']
|
108
|
+
end
|
89
109
|
end
|
90
110
|
|
91
111
|
def ipv6_from_interface(interface)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAnsible
|
4
|
+
class ImportRolesAndVariablesErrorNotification < ::UINotifications::Base
|
5
|
+
private
|
6
|
+
|
7
|
+
def initialize(error, task)
|
8
|
+
@job_error = error
|
9
|
+
@subject = task
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
::Notification.create!(
|
14
|
+
:audience => Notification::AUDIENCE_USER,
|
15
|
+
:notification_blueprint => blueprint,
|
16
|
+
:initiator => initiator,
|
17
|
+
:message => message,
|
18
|
+
:subject => subject
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def blueprint
|
23
|
+
name = 'Sync_roles_and_variables_failed'
|
24
|
+
@blueprint ||= NotificationBlueprint.unscoped.find_by(:name => name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def message
|
28
|
+
_("Failed to import roles and variables Due to: #{@job_error}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAnsible
|
4
|
+
class ImportRolesAndVariablesSuccessNotification < ::UINotifications::Base
|
5
|
+
private
|
6
|
+
|
7
|
+
def create
|
8
|
+
::Notification.create!(
|
9
|
+
:audience => Notification::AUDIENCE_USER,
|
10
|
+
:notification_blueprint => blueprint,
|
11
|
+
:initiator => initiator,
|
12
|
+
:message => message,
|
13
|
+
:subject => subject
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def blueprint
|
18
|
+
name = 'Sync_roles_and_variables_successfully'
|
19
|
+
@blueprint ||= NotificationBlueprint.unscoped.find_by(:name => name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def message
|
23
|
+
blueprint.message
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -99,7 +99,7 @@ module ForemanAnsible
|
|
99
99
|
params = {
|
100
100
|
'ansible_user' => host_setting(host, 'remote_execution_ssh_user'),
|
101
101
|
'ansible_become_method' => host_setting(host, 'remote_execution_effective_user_method'),
|
102
|
-
'ansible_ssh_private_key_file' =>
|
102
|
+
'ansible_ssh_private_key_file' => ansible_ssh_private_key(host),
|
103
103
|
'ansible_port' => host_setting(host, 'remote_execution_ssh_port'),
|
104
104
|
'ansible_host' => AnsibleProvider.find_ip_or_hostname(host)
|
105
105
|
}
|
@@ -122,13 +122,9 @@ module ForemanAnsible
|
|
122
122
|
result
|
123
123
|
end
|
124
124
|
|
125
|
-
def
|
125
|
+
def ansible_ssh_private_key(host)
|
126
126
|
ansible_private_file = host_setting(host, 'ansible_ssh_private_key_file')
|
127
|
-
|
128
|
-
ansible_private_file
|
129
|
-
else
|
130
|
-
ForemanRemoteExecutionCore.settings[:ssh_identity_key_file]
|
131
|
-
end
|
127
|
+
ansible_private_file unless ansible_private_file.empty?
|
132
128
|
end
|
133
129
|
|
134
130
|
private
|
@@ -80,8 +80,14 @@ module ForemanAnsible
|
|
80
80
|
facts[:ansible_os_name].tr(" \n\t", '') ||
|
81
81
|
facts[:ansible_distribution].tr(" \n\t", '')
|
82
82
|
else
|
83
|
-
facts[:
|
84
|
-
|
83
|
+
distribution = facts[:ansible_lsb].try(:[], 'id') || facts[:ansible_distribution]
|
84
|
+
|
85
|
+
if distribution == 'RedHat' &&
|
86
|
+
facts[:ansible_lsb].try(:[], 'id') == 'RedHatEnterpriseWorkstation'
|
87
|
+
distribution += '_Workstation'
|
88
|
+
end
|
89
|
+
|
90
|
+
distribution
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|