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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ansible_roles_controller.rb +12 -8
  3. data/app/controllers/ansible_variables_controller.rb +4 -0
  4. data/app/controllers/api/v2/ansible_inventories_controller.rb +2 -2
  5. data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
  6. data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
  7. data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
  8. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +42 -56
  9. data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
  10. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
  11. data/app/jobs/sync_roles_and_variables.rb +20 -0
  12. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +10 -7
  13. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +19 -4
  14. data/app/models/foreman_ansible/ansible_provider.rb +52 -2
  15. data/app/models/host_ansible_role.rb +1 -0
  16. data/app/models/hostgroup_ansible_role.rb +1 -0
  17. data/app/models/setting/ansible.rb +9 -0
  18. data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
  19. data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
  20. data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
  21. data/app/services/foreman_ansible/fact_parser.rb +21 -1
  22. data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
  23. data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
  24. data/app/services/foreman_ansible/inventory_creator.rb +3 -7
  25. data/app/services/foreman_ansible/operating_system_parser.rb +8 -2
  26. data/app/services/foreman_ansible/roles_importer.rb +3 -2
  27. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
  28. data/app/services/foreman_ansible/variables_importer.rb +36 -1
  29. data/app/views/ansible_roles/import.html.erb +10 -50
  30. data/app/views/ansible_variables/index.html.erb +1 -2
  31. data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
  32. data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +8 -17
  33. data/app/views/foreman_ansible/config_reports/_ansible.html.erb +24 -8
  34. data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
  35. data/app/views/foreman_ansible/job_templates/ansible_roles_-_ansible_default.erb +4 -0
  36. data/app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb +1 -1
  37. data/app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb +2 -3
  38. data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
  39. data/config/routes.rb +5 -4
  40. data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
  41. data/db/seeds.d/100_common_parameters.rb +7 -0
  42. data/db/seeds.d/90_notification_blueprints.rb +19 -1
  43. data/lib/foreman_ansible/engine.rb +1 -1
  44. data/lib/foreman_ansible/register.rb +7 -5
  45. data/lib/foreman_ansible/version.rb +1 -1
  46. data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
  47. data/locale/ca/foreman_ansible.po +1 -1
  48. data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
  49. data/locale/cs_CZ/foreman_ansible.po +1 -1
  50. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  51. data/locale/de/foreman_ansible.po +1 -1
  52. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  53. data/locale/en/foreman_ansible.po +1 -1
  54. data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
  55. data/locale/en_GB/foreman_ansible.po +1 -1
  56. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  57. data/locale/es/foreman_ansible.po +1 -1
  58. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  59. data/locale/fr/foreman_ansible.po +1 -1
  60. data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
  61. data/locale/gl/foreman_ansible.po +1 -1
  62. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  63. data/locale/it/foreman_ansible.po +1 -1
  64. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  65. data/locale/ja/foreman_ansible.po +1 -1
  66. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  67. data/locale/ko/foreman_ansible.po +1 -1
  68. data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
  69. data/locale/nl_NL/foreman_ansible.po +1 -1
  70. data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
  71. data/locale/pl/foreman_ansible.po +1 -1
  72. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  73. data/locale/pt_BR/foreman_ansible.po +1 -1
  74. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  75. data/locale/ru/foreman_ansible.po +1 -1
  76. data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
  77. data/locale/sv_SE/foreman_ansible.po +1 -1
  78. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  79. data/locale/zh_CN/foreman_ansible.po +1 -1
  80. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  81. data/locale/zh_TW/foreman_ansible.po +1 -1
  82. data/package.json +13 -42
  83. data/test/factories/ansible_roles.rb +12 -0
  84. data/test/factories/host_ansible_enhancements.rb +23 -0
  85. data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
  86. data/test/functional/ansible_variables_controller_test.rb +0 -15
  87. data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
  88. data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
  89. data/test/functional/api/v2/hosts_controller_test.rb +9 -8
  90. data/test/functional/hosts_controller_test.rb +10 -6
  91. data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
  92. data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
  93. data/test/unit/helpers/ansible_reports_helper_test.rb +4 -30
  94. data/test/unit/host_ansible_role_test.rb +2 -1
  95. data/test/unit/hostgroup_ansible_role_test.rb +2 -1
  96. data/test/unit/ignore_roles_test.rb +43 -0
  97. data/test/unit/import_roles_and_variables.rb +60 -0
  98. data/test/unit/services/ansible_variables_importer_test.rb +13 -0
  99. data/test/unit/services/api_roles_importer_test.rb +22 -5
  100. data/test/unit/services/fact_parser_test.rb +16 -0
  101. data/test/unit/services/inventory_creator_test.rb +15 -7
  102. data/test/unit/services/ui_roles_importer_test.rb +2 -2
  103. data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.js +35 -0
  104. data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.scss +6 -0
  105. data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.test.js +14 -0
  106. data/webpack/components/AnsibleHostDetail/index.js +6 -0
  107. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
  108. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
  109. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
  110. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
  111. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
  112. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
  113. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
  114. data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
  115. data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
  116. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +25 -27
  117. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
  118. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +20 -14
  119. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
  120. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
  121. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
  122. data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
  123. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +6 -4
  124. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +1 -9
  125. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +3 -16
  126. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -8
  127. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
  128. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
  129. data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +1 -1
  130. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
  131. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +1 -1
  132. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
  133. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
  134. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
  135. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +4 -1
  136. data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +1 -1
  137. data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
  138. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsiblePermissionDenied.test.js.snap +2 -0
  139. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
  140. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
  141. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AvailableRolesList.test.js.snap +5 -0
  142. data/webpack/components/AnsibleRolesSwitcher/index.js +4 -8
  143. data/webpack/global_index.js +12 -0
  144. data/webpack/index.js +6 -13
  145. metadata +54 -30
  146. data/app/views/ansible_variables/import.html.erb +0 -56
  147. data/test/unit/lib/foreman_ansible_core/ansible_runner_test.rb +0 -51
  148. data/test/unit/lib/foreman_ansible_core/command_creator_test.rb +0 -64
  149. data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +0 -110
  150. data/webpack/__mocks__/foremanReact/common/I18n.js +0 -1
  151. data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +0 -2
  152. data/webpack/__mocks__/foremanReact/components/common/EmptyState.js +0 -5
  153. data/webpack/test_setup.js +0 -12
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class CommandCreatorTest < ActiveSupport::TestCase
6
- let(:inventory_file) { 'test_inventory' }
7
- let(:playbook_file) { 'test_palybook.yml' }
8
- subject do
9
- ForemanAnsibleCore::CommandCreator.new(inventory_file, playbook_file, {})
10
- end
11
-
12
- test 'returns a command array including the ansible-playbook command' do
13
- assert command_parts.include?('ansible-playbook')
14
- end
15
-
16
- test 'the last argument is the playbook_file' do
17
- assert command_parts.last == playbook_file
18
- end
19
-
20
- describe 'environment variables' do
21
- let(:environment_variables) { subject.command.first }
22
-
23
- test 'has a JSON_INVENTORY_FILE set' do
24
- assert environment_variables['JSON_INVENTORY_FILE']
25
- end
26
-
27
- test 'has no ANSIBLE_CALLBACK_WHITELIST set by default' do
28
- assert_not environment_variables['ANSIBLE_CALLBACK_WHITELIST']
29
- end
30
-
31
- test 'with a REX command it sets ANSIBLE_CALLBACK_WHITELIST to empty' do
32
- set_command_options(:remote_execution_command, true)
33
- assert environment_variables['ANSIBLE_CALLBACK_WHITELIST']
34
- end
35
- end
36
-
37
- describe 'command options' do
38
- it 'can have verbosity set' do
39
- level = '3'
40
- level_string = Array.new(level.to_i).map { 'v' }.join
41
- set_command_options(:verbosity_level, level)
42
- assert command_parts.any? do |part|
43
- part == "-#{level_string}"
44
- end
45
- end
46
-
47
- it 'can have a timeout set' do
48
- timeout = '5555'
49
- set_command_options(:timeout, timeout)
50
- assert command_parts.include?(timeout)
51
- end
52
- end
53
-
54
- private
55
-
56
- def command_parts
57
- subject.command.flatten.map(&:to_s)
58
- end
59
-
60
- def set_command_options(option, value)
61
- subject.instance_eval("@options[:#{option}] = \"#{value}\"",
62
- __FILE__, __LINE__ - 1)
63
- end
64
- end
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- # Playbook Runner - this class uses foreman_tasks_core
6
- # to run playbooks
7
- class PlaybookRunnerTest < ActiveSupport::TestCase
8
- context 'roles dir' do
9
- test 'reads default when none provided' do
10
- ForemanAnsibleCore::Runner::Playbook.any_instance.stubs(:unknown_hosts).
11
- returns([])
12
- File.expects(:exist?).with(Dir.home).returns(true)
13
- ForemanAnsibleCore::Runner::Playbook.any_instance.expects(:rebuild_secrets).returns(nil)
14
- runner = ForemanAnsibleCore::Runner::Playbook.new(nil, nil, :suspended_action => nil)
15
- assert '/etc/ansible', runner.instance_variable_get('@ansible_dir')
16
- end
17
- end
18
-
19
- context 'working_dir' do
20
- setup do
21
- ForemanAnsibleCore::Runner::Playbook.any_instance.stubs(:unknown_hosts).
22
- returns([])
23
- end
24
-
25
- test 'creates temp one if not provided' do
26
- Dir.expects(:mktmpdir)
27
- File.expects(:exist?).with(Dir.home).returns(true)
28
- ForemanAnsibleCore::Runner::Playbook.any_instance.expects(:rebuild_secrets).returns(nil)
29
- ForemanAnsibleCore::Runner::Playbook.new(nil, nil, :suspended_action => nil)
30
- end
31
-
32
- test 'reads it when provided' do
33
- settings = { :working_dir => '/foo', :ansible_dir => '/etc/foo' }
34
- ForemanAnsibleCore.expects(:settings).returns(settings)
35
- File.expects(:exist?).with(settings[:ansible_dir]).returns(true)
36
- Dir.expects(:mktmpdir).never
37
- ForemanAnsibleCore::Runner::Playbook.any_instance.expects(:rebuild_secrets).returns(nil)
38
- runner = ForemanAnsibleCore::Runner::Playbook.new(nil, nil, :suspended_action => nil)
39
- assert '/foo', runner.instance_variable_get('@working_dir')
40
- end
41
- end
42
-
43
- context 'TOFU policy' do # Trust On First Use
44
- setup do
45
- @inventory = { 'all' => { 'hosts' => ['foreman.example.com'] } }
46
- @output = StringIO.new
47
- logger = Logger.new(@output)
48
- ForemanAnsibleCore::Runner::Playbook.any_instance.stubs(:logger).
49
- returns(logger)
50
- end
51
-
52
- test 'ignores known hosts' do
53
- Net::SSH::KnownHosts.expects(:search_for).
54
- with('foreman.example.com').returns(['somekey'])
55
- ForemanAnsibleCore::Runner::Playbook.any_instance.
56
- expects(:add_to_known_hosts).never
57
- ForemanAnsibleCore::Runner::Playbook.any_instance.expects(:rebuild_secrets).returns(@inventory)
58
- ForemanAnsibleCore::Runner::Playbook.new(@inventory, nil, :suspended_action => nil)
59
- end
60
-
61
- test 'adds unknown hosts to known_hosts' do
62
- Net::SSH::KnownHosts.expects(:search_for).
63
- with('foreman.example.com').returns([])
64
- ForemanAnsibleCore::Runner::Playbook.any_instance.
65
- expects(:add_to_known_hosts).with('foreman.example.com')
66
- ForemanAnsibleCore::Runner::Playbook.any_instance.expects(:rebuild_secrets).returns(@inventory)
67
- ForemanAnsibleCore::Runner::Playbook.new(@inventory, nil, :suspended_action => nil)
68
- end
69
-
70
- test 'logs error when it cannot add to known_hosts' do
71
- Net::SSH::KnownHosts.expects(:search_for).
72
- with('foreman.example.com').returns([])
73
- Net::SSH::Transport::Session.expects(:new).with('foreman.example.com').
74
- raises(Net::Error)
75
- ForemanAnsibleCore::Runner::Playbook.any_instance.expects(:rebuild_secrets).returns(@inventory)
76
- ForemanAnsibleCore::Runner::Playbook.new(@inventory, nil, :suspended_action => nil)
77
- assert_match(
78
- /ERROR.*Failed to save host key for foreman.example.com: Net::Error/,
79
- @output.string
80
- )
81
- end
82
- end
83
-
84
- context 'rebuild secrets' do
85
- let(:inventory) do
86
- { 'all' => { 'hosts' => ['foreman.example.com'] },
87
- '_meta' => { 'hostvars' => { 'foreman.example.com' => {} } } }
88
- end
89
- let(:secrets) do
90
- host_secrets = { 'ansible_password' => 'letmein', 'ansible_become_password' => 'iamroot' }
91
- { 'per-host' => { 'foreman.example.com' => host_secrets } }
92
- end
93
- let(:runner) { ForemanAnsibleCore::Runner::Playbook.allocate }
94
-
95
- test 'uses secrets from inventory' do
96
- test_inventory = inventory.merge('ssh_password' => 'sshpass', 'effective_user_password' => 'mypass')
97
- rebuilt = runner.send(:rebuild_secrets, test_inventory, secrets)
98
- host_vars = rebuilt.dig('_meta', 'hostvars', 'foreman.example.com')
99
- assert_equal 'sshpass', host_vars['ansible_password']
100
- assert_equal 'mypass', host_vars['ansible_become_password']
101
- end
102
-
103
- test 'host secrets are used when not overriden by inventory secrest' do
104
- rebuilt = runner.send(:rebuild_secrets, inventory, secrets)
105
- host_vars = rebuilt.dig('_meta', 'hostvars', 'foreman.example.com')
106
- assert_equal 'letmein', host_vars['ansible_password']
107
- assert_equal 'iamroot', host_vars['ansible_become_password']
108
- end
109
- end
110
- end
@@ -1 +0,0 @@
1
- export const translate = s => s;
@@ -1,2 +0,0 @@
1
- const PaginationWrapper = () => jest.fn();
2
- export default PaginationWrapper;
@@ -1,5 +0,0 @@
1
- const EmptyState = () => jest.fn();
2
-
3
- export const EmptyStatePattern = () => jest.fn();
4
-
5
- export default EmptyState;
@@ -1,12 +0,0 @@
1
- import 'core-js/shim';
2
- import 'regenerator-runtime/runtime';
3
-
4
- import { configure } from 'enzyme';
5
- import Adapter from 'enzyme-adapter-react-16';
6
-
7
- configure({ adapter: new Adapter() });
8
-
9
- // Mocking translation function
10
- global.__ = str => str;
11
- global.n__ = str => str;
12
- global.Jed = { sprintf: str => str };