foreman_ansible 3.0.9 → 4.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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/controllers/api/v2/ansible_inventories_controller.rb +50 -0
  4. data/app/models/ansible_variable.rb +1 -0
  5. data/app/models/foreman_ansible/ansible_provider.rb +25 -1
  6. data/app/models/foreman_ansible/fact_name.rb +5 -1
  7. data/app/models/setting/ansible.rb +81 -88
  8. data/app/services/foreman_ansible/fact_importer.rb +5 -8
  9. data/app/services/foreman_ansible/fact_parser.rb +16 -4
  10. data/app/services/foreman_ansible/inventory_creator.rb +1 -12
  11. data/app/views/foreman_ansible/job_templates/run_playbook-ansible_default.erb +17 -0
  12. data/config/routes.rb +1 -2
  13. data/db/migrate/20190328114657_remove_top_level_ansible_variables_setting.rb +1 -1
  14. data/db/migrate/20191010074208_remove_ansible_implementation_setting.rb +5 -0
  15. data/db/seeds.d/75_job_templates.rb +2 -2
  16. data/lib/foreman_ansible/register.rb +5 -2
  17. data/lib/foreman_ansible/remote_execution.rb +6 -0
  18. data/lib/foreman_ansible/version.rb +1 -1
  19. data/locale/Makefile +7 -0
  20. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  21. data/locale/de/foreman_ansible.po +1 -1
  22. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  23. data/locale/en/foreman_ansible.po +1 -1
  24. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  25. data/locale/es/foreman_ansible.po +1 -1
  26. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  27. data/locale/fr/foreman_ansible.po +1 -1
  28. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  29. data/locale/it/foreman_ansible.po +1 -1
  30. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  31. data/locale/ja/foreman_ansible.po +1 -1
  32. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  33. data/locale/ko/foreman_ansible.po +1 -1
  34. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  35. data/locale/pt_BR/foreman_ansible.po +1 -1
  36. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  37. data/locale/ru/foreman_ansible.po +1 -1
  38. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  39. data/locale/zh_CN/foreman_ansible.po +1 -1
  40. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  41. data/locale/zh_TW/foreman_ansible.po +1 -1
  42. data/package.json +3 -3
  43. data/test/unit/ansible_provider_test.rb +16 -0
  44. data/test/unit/ansible_variable_test.rb +10 -0
  45. data/test/unit/lib/foreman_ansible_core/ansible_runner_test.rb +51 -0
  46. data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +34 -1
  47. data/test/unit/services/fact_importer_test.rb +4 -2
  48. data/test/unit/services/fact_parser_test.rb +57 -4
  49. data/test/unit/services/inventory_creator_test.rb +10 -25
  50. data/webpack/__mocks__/foremanReact/common/I18n.js +1 -0
  51. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +1 -0
  52. data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.js +1 -0
  53. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +1 -0
  54. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +18 -23
  55. data/webpack/index.js +5 -4
  56. metadata +15 -11
  57. data/app/lib/actions/foreman_ansible/helpers/host_common.rb +0 -39
@@ -71,13 +71,12 @@ module ForemanAnsible
71
71
  '_timestamp' => '2018-10-29 20:01:51 +0100',
72
72
  'ansible_facts' =>
73
73
  {
74
- 'ansible_interfaces' => [
75
- 'eth0'
76
- ],
74
+ 'ansible_interfaces' => %w[eth0 eth1 eth2 bond0],
77
75
  'ansible_eth0' => {
78
76
  'active' => true,
79
77
  'device' => 'eth0',
80
- "macaddress" => '52:54:00:04:55:37',
78
+ 'macaddress' => '52:54:00:04:55:37',
79
+ 'perm_macaddress' => '52:54:00:04:55:37',
81
80
  'ipv4' => {
82
81
  'address' => '10.10.0.10',
83
82
  'netmask' => '255.255.0.0',
@@ -93,6 +92,45 @@ module ForemanAnsible
93
92
  'mtu' => 1500,
94
93
  'promisc' => false,
95
94
  'type' => 'ether'
95
+ },
96
+ 'ansible_eth1' => {
97
+ 'active' => true,
98
+ 'device' => 'eth1',
99
+ 'macaddress' => '52:54:00:04:55:38',
100
+ 'perm_macaddress' => '52:54:00:04:55:38',
101
+ 'mtu' => 1500,
102
+ 'promisc' => false,
103
+ 'type' => 'ether'
104
+ },
105
+ 'ansible_eth2' => {
106
+ 'active' => true,
107
+ 'device' => 'eth2',
108
+ 'macaddress' => '52:54:00:04:55:38',
109
+ 'perm_macaddress' => '52:54:00:04:55:39',
110
+ 'mtu' => 1500,
111
+ 'promisc' => false,
112
+ 'type' => 'ether'
113
+ },
114
+ 'ansible_bond0' => {
115
+ 'active' => true,
116
+ 'device' => 'bond0',
117
+ 'macaddress' => '52:54:00:04:55:38',
118
+ 'ipv4' => {
119
+ 'address' => '10.10.0.11',
120
+ 'netmask' => '255.255.0.0',
121
+ 'network' => '10.10.0.0'
122
+ },
123
+ 'ipv6' => [
124
+ {
125
+ 'address' => 'fd00::5054:00ff:fe04:5538',
126
+ 'prefix' => '64',
127
+ 'scope' => 'host'
128
+ }
129
+ ],
130
+ 'mtu' => 1500,
131
+ 'promisc' => false,
132
+ 'slaves' => %w[eth1 eth2],
133
+ 'type' => 'bonding'
96
134
  }
97
135
  }
98
136
  )
@@ -105,6 +143,21 @@ module ForemanAnsible
105
143
  assert_equal '10.10.0.10', interface['ipaddress']
106
144
  assert_equal 'fd00::5054:00ff:fe04:5537', interface['ipaddress6']
107
145
  end
146
+
147
+ test 'Parses MAC address correctly when bonded' do
148
+ iut0 = 'eth0'.dup
149
+ iut1 = 'eth1'.dup
150
+ iut2 = 'eth2'.dup
151
+ but0 = 'bond0'.dup
152
+ interface_eth0 = @facts_parser.get_facts_for_interface(iut0)
153
+ interface_eth1 = @facts_parser.get_facts_for_interface(iut1)
154
+ interface_eth2 = @facts_parser.get_facts_for_interface(iut2)
155
+ interface_bond0 = @facts_parser.get_facts_for_interface(but0)
156
+ assert_equal '52:54:00:04:55:37', interface_eth0['macaddress']
157
+ assert_equal '52:54:00:04:55:38', interface_eth1['macaddress']
158
+ assert_equal '52:54:00:04:55:39', interface_eth2['macaddress']
159
+ assert_equal '52:54:00:04:55:38', interface_bond0['macaddress']
160
+ end
108
161
  end
109
162
 
110
163
  # Tests for Debian parser
@@ -41,17 +41,14 @@ module ForemanAnsible
41
41
  returns(2222).at_least_once
42
42
  Setting.expects(:[]).with('remote_execution_ssh_user').
43
43
  returns('root').at_least_once
44
- Setting.expects(:[]).with('remote_execution_ssh_password').
45
- returns('asafepassword').at_least_once
46
- Setting.expects(:[]).with('remote_execution_sudo_password').
47
- returns('foobar').at_least_once
48
44
  Setting.expects(:[]).with('ansible_winrm_server_cert_validation').
49
45
  returns(true).at_least_once
50
46
  Setting.expects(:[]).with('ansible_connection').
51
47
  returns('ssh').at_least_once
48
+ Setting.expects(:[]).with('remote_execution_effective_user_method').
49
+ returns('sudo').at_least_once
52
50
  @host.expects(:host_params).returns(extra_options).at_least_once
53
- @template_invocation.job_invocation.expects(:password).
54
- returns(nil).at_least_once
51
+ @template_invocation.job_invocation.expects(:password).never
55
52
  inventory = ForemanAnsible::InventoryCreator.new(@host,
56
53
  @template_invocation)
57
54
  connection_params = inventory.connection_params(@host)
@@ -71,26 +68,12 @@ module ForemanAnsible
71
68
  connection_params['ansible_ssh_private_key_file']
72
69
  assert_equal extra_options['ansible_port'],
73
70
  connection_params['ansible_port']
74
- assert_equal Setting['remote_execution_ssh_password'],
75
- connection_params['ansible_ssh_pass']
76
- assert_equal Setting['remote_execution_sudo_password'],
77
- connection_params['ansible_sudo_pass']
78
71
  assert_equal Setting['ansible_winrm_server_cert_validation'],
79
72
  connection_params['ansible_winrm_server_cert_validation']
80
- end
81
-
82
- test 'job invocation ssh password is passed when available' do
83
- inventory = ForemanAnsible::InventoryCreator.new(@host,
84
- @template_invocation)
85
- assert_equal(@template_invocation.job_invocation.password,
86
- inventory.rex_ssh_password(@host))
87
- end
88
-
89
- test 'job invocation sudo password is passed when available' do
90
- inventory = ForemanAnsible::InventoryCreator.new(@host,
91
- @template_invocation)
92
- assert_equal(@template_invocation.job_invocation.sudo_password,
93
- inventory.rex_sudo_password(@host))
73
+ assert_equal Setting['remote_execution_effective_user_method'],
74
+ connection_params['ansible_become_method']
75
+ refute connection_params.key?('ansible_ssh_pass')
76
+ refute connection_params.key?('ansible_sudo_pass')
94
77
  end
95
78
 
96
79
  test 'ssh private key is passed when available' do
@@ -105,6 +88,8 @@ module ForemanAnsible
105
88
  returns('root')
106
89
  host.params.expects(:[]).with('remote_execution_ssh_port').
107
90
  returns('2222')
91
+ host.params.expects(:[]).with('remote_execution_effective_user_method').
92
+ returns('sudo')
108
93
  connection_params = inventory.connection_params(host)
109
94
  assert_equal path_to_key,
110
95
  connection_params['ansible_ssh_private_key_file']
@@ -123,7 +108,7 @@ module ForemanAnsible
123
108
  template_invocation = FactoryBot.build(:template_invocation,
124
109
  :template => job_template,
125
110
  :job_invocation => job_invocation)
126
- job_invocation.expects(:password).returns(nil).at_least_once
111
+ job_invocation.expects(:password).never
127
112
  input_value = FactoryBot.create(
128
113
  :template_invocation_input_value,
129
114
  :template_invocation => template_invocation,
@@ -0,0 +1 @@
1
+ export const translate = s => s;
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { Grid, Row, Col } from 'patternfly-react';
3
3
  import { lowerCase } from 'lodash';
4
4
  import PropTypes from 'prop-types';
5
+ import { translate as __ } from 'foremanReact/common/I18n';
5
6
 
6
7
  import AvailableRolesList from './components/AvailableRolesList';
7
8
  import AssignedRolesList from './components/AssignedRolesList';
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { translate as __ } from 'foremanReact/common/I18n';
2
3
  import { EmptyStatePattern as EmptyState } from 'foremanReact/components/common/EmptyState';
3
4
 
4
5
  const AnsiblePermissionDenied = props => {
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { ListView, Tooltip, OverlayTrigger } from 'patternfly-react';
3
3
  import classNames from 'classnames';
4
+ import { translate as __ } from 'foremanReact/common/I18n';
4
5
 
5
6
  import AnsibleRoleActionButton from './AnsibleRoleActionButton';
6
7
  import '../AnsibleRolesSwitcher.scss';
@@ -16,28 +16,6 @@ const AssignedRolesList = ({
16
16
  }) => {
17
17
  const directlyAssignedRoles = assignedRoles.filter(role => !role.inherited);
18
18
 
19
- const inputFields = (directlyAssignedRoles, resourceName) => {
20
- let result;
21
- if (isEmpty(directlyAssignedRoles)) {
22
- result = <input type="hidden" name={`${resourceName}[ansible_role_ids][]`} value=""/>
23
- } else {
24
- result = directlyAssignedRoles.map(role => (
25
- <input
26
- key={role.id}
27
- type="hidden"
28
- name={`${resourceName}[ansible_role_ids][]`}
29
- value={role.id}
30
- />
31
- ))
32
- }
33
-
34
- return (
35
- <div>
36
- { result }
37
- </div>
38
- );
39
- }
40
-
41
19
  return (
42
20
  <div>
43
21
  <ListView>
@@ -60,7 +38,24 @@ const AssignedRolesList = ({
60
38
  />
61
39
  ))}
62
40
  </ListView>
63
- { inputFields(directlyAssignedRoles, resourceName) }
41
+ <div>
42
+ {isEmpty(directlyAssignedRoles) ? (
43
+ <input
44
+ type="hidden"
45
+ name={`${resourceName}[ansible_role_ids][]`}
46
+ value=""
47
+ />
48
+ ) : (
49
+ directlyAssignedRoles.map(role => (
50
+ <input
51
+ key={role.id}
52
+ type="hidden"
53
+ name={`${resourceName}[ansible_role_ids][]`}
54
+ value={role.id}
55
+ />
56
+ ))
57
+ )}
58
+ </div>
64
59
  </div>
65
60
  );
66
61
  };
@@ -1,11 +1,12 @@
1
+ import $ from 'jquery';
1
2
  import componentRegistry from 'foremanReact/components/componentRegistry';
2
3
  import injectReducer from 'foremanReact/redux/reducers/registerReducer';
3
4
  import ReportJsonViewer from './components/ReportJsonViewer';
4
5
  import AnsibleRolesSwitcher from './components/AnsibleRolesSwitcher';
5
- import $ from 'jquery';
6
-
7
6
  import reducer from './reducer';
8
7
 
8
+ const { tfm } = window;
9
+
9
10
  componentRegistry.register({
10
11
  name: 'ReportJsonViewer',
11
12
  type: ReportJsonViewer,
@@ -17,7 +18,7 @@ componentRegistry.register({
17
18
 
18
19
  injectReducer('foremanAnsible', reducer);
19
20
 
20
- window.tfm.initAnsibleRoleSwitcher = () => {
21
+ tfm.initAnsibleRoleSwitcher = () => {
21
22
  $(document).on('ContentLoad', evt => {
22
23
  tfm.reactMounter.mount(
23
24
  'AnsibleRolesSwitcher',
@@ -25,4 +26,4 @@ window.tfm.initAnsibleRoleSwitcher = () => {
25
26
  $('#ansible_roles_switcher').data('roles')
26
27
  );
27
28
  });
28
- }
29
+ };
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: 3.0.9
4
+ version: 4.0.0
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: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2019-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -72,20 +72,20 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.7.0
75
+ version: 2.0.0
76
76
  - - "<"
77
77
  - !ruby/object:Gem::Version
78
- version: '2.0'
78
+ version: '3.0'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 1.7.0
85
+ version: 2.0.0
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
- version: '2.0'
88
+ version: '3.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: ipaddress
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +140,6 @@ files:
140
140
  - app/helpers/foreman_ansible/ansible_reports_helper.rb
141
141
  - app/helpers/foreman_ansible/ansible_roles_helper.rb
142
142
  - app/helpers/foreman_ansible/hosts_helper_extensions.rb
143
- - app/lib/actions/foreman_ansible/helpers/host_common.rb
144
143
  - app/lib/actions/foreman_ansible/helpers/play_roles_description.rb
145
144
  - app/lib/proxy_api/ansible.rb
146
145
  - app/models/ansible_role.rb
@@ -213,6 +212,7 @@ files:
213
212
  - app/views/foreman_ansible/job_templates/power_action_-_ansible_default.erb
214
213
  - app/views/foreman_ansible/job_templates/puppet_run_once_-_ansible_default.erb
215
214
  - app/views/foreman_ansible/job_templates/run_command_-_ansible_default.erb
215
+ - app/views/foreman_ansible/job_templates/run_playbook-ansible_default.erb
216
216
  - app/views/foreman_ansible/job_templates/service_action_-_ansible_default.erb
217
217
  - app/views/ui_ansible_roles/index.json.rabl
218
218
  - app/views/ui_ansible_roles/main.json.rabl
@@ -229,6 +229,7 @@ files:
229
229
  - db/migrate/20180628125416_add_ansible_role_id_to_lookup_keys.rb
230
230
  - db/migrate/20190318094437_add_imported_attr_to_ansible_variables.rb
231
231
  - db/migrate/20190328114657_remove_top_level_ansible_variables_setting.rb
232
+ - db/migrate/20191010074208_remove_ansible_implementation_setting.rb
232
233
  - db/seeds.d/62_ansible_proxy_feature.rb
233
234
  - db/seeds.d/75_job_templates.rb
234
235
  - db/seeds.d/90_notification_blueprints.rb
@@ -291,6 +292,7 @@ files:
291
292
  - test/unit/helpers/ansible_reports_helper_test.rb
292
293
  - test/unit/host_ansible_role_test.rb
293
294
  - test/unit/hostgroup_ansible_role_test.rb
295
+ - test/unit/lib/foreman_ansible_core/ansible_runner_test.rb
294
296
  - test/unit/lib/foreman_ansible_core/command_creator_test.rb
295
297
  - test/unit/lib/foreman_ansible_core/playbook_runner_test.rb
296
298
  - test/unit/lib/proxy_api/ansible_test.rb
@@ -305,6 +307,7 @@ files:
305
307
  - test/unit/services/roles_importer_test.rb
306
308
  - test/unit/services/structured_fact_importer_test.rb
307
309
  - test/unit/services/ui_roles_importer_test.rb
310
+ - webpack/__mocks__/foremanReact/common/I18n.js
308
311
  - webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js
309
312
  - webpack/__mocks__/foremanReact/components/common/EmptyState.js
310
313
  - webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js
@@ -389,22 +392,23 @@ test_files:
389
392
  - test/unit/concerns/hostgroup_extensions_test.rb
390
393
  - test/unit/helpers/ansible_reports_helper_test.rb
391
394
  - test/unit/lib/foreman_ansible_core/command_creator_test.rb
395
+ - test/unit/lib/foreman_ansible_core/ansible_runner_test.rb
392
396
  - test/unit/lib/foreman_ansible_core/playbook_runner_test.rb
393
397
  - test/unit/lib/proxy_api/ansible_test.rb
394
398
  - test/unit/services/ansible_report_importer_test.rb
395
399
  - test/unit/services/api_roles_importer_test.rb
396
- - test/unit/services/fact_importer_test.rb
397
- - test/unit/services/fact_parser_test.rb
398
400
  - test/unit/services/fact_sparser_test.rb
399
401
  - test/unit/services/insights_plan_runner_test.rb
400
402
  - test/unit/services/roles_importer_test.rb
401
403
  - test/unit/services/structured_fact_importer_test.rb
402
404
  - test/unit/services/ui_roles_importer_test.rb
403
405
  - test/unit/services/ansible_variables_importer_test.rb
406
+ - test/unit/services/fact_importer_test.rb
407
+ - test/unit/services/fact_parser_test.rb
404
408
  - test/unit/services/inventory_creator_test.rb
405
- - test/unit/ansible_provider_test.rb
406
409
  - test/unit/ansible_role_test.rb
407
- - test/unit/ansible_variable_test.rb
408
410
  - test/unit/host_ansible_role_test.rb
409
411
  - test/unit/hostgroup_ansible_role_test.rb
412
+ - test/unit/ansible_provider_test.rb
413
+ - test/unit/ansible_variable_test.rb
410
414
  - test/test_plugin_helper.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Actions
4
- module ForemanAnsible
5
- module Helpers
6
- # Shared task methods between hostgroup and host roles actions
7
- module HostCommon
8
- def finalize
9
- return unless delegated_output[:exit_status].to_s != '0'
10
- error! _('Playbook execution failed')
11
- end
12
-
13
- def rescue_strategy
14
- ::Dynflow::Action::Rescue::Fail
15
- end
16
-
17
- def humanized_name
18
- _('Play Ansible roles')
19
- end
20
-
21
- def humanized_output
22
- continuous_output.humanize
23
- end
24
-
25
- def fill_continuous_output(continuous_output)
26
- delegated_output.fetch('result', []).each do |raw_output|
27
- continuous_output.add_raw_output(raw_output)
28
- end
29
- rescue StandardError => e
30
- continuous_output.add_exception(_('Error loading data from proxy'), e)
31
- end
32
-
33
- def find_options
34
- { :verbosity_level => Setting[:ansible_verbosity] }
35
- end
36
- end
37
- end
38
- end
39
- end