-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #28287 - Import Ansible roles and variables in one step
This PR Includes: - The ability to sync roles and their variables from Capsule in one step - React table to present all the roles and variables that need to be synced. - Removing the 'import variables' view from the index variables page.
- Loading branch information
Showing
23 changed files
with
719 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/helpers/foreman_ansible/ansible_roles_data_preparations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
module ForemanAnsible | ||
module AnsibleRolesDataPreparations | ||
VARIABLE_ACTION_NAMES = { 'new' => N_('Add'), 'obsolete' => N_('Remove'), 'update' => N_('Update') }.freeze | ||
ROLE_ACTION_NAMES = { 'new' => N_('Import Role'), 'obsolete' => N_('Remove Role'), 'old' => N_('Update Role Variables') }.freeze | ||
|
||
def get_variable_action(kind) | ||
_(VARIABLE_ACTION_NAMES[kind]) | ||
end | ||
|
||
def get_role_action(kind) | ||
_(ROLE_ACTION_NAMES[kind]) | ||
end | ||
|
||
def get_old_roles_variables(imported_variables, role) | ||
variables = { 'Add' => [], 'Remove' => [], 'Update' => [] } | ||
imported_variables.each do |kind, temp_variables| | ||
temp_variables.each do |temp_variable| | ||
variables[get_variable_action(kind)].append(temp_variable.key) if temp_variable.ansible_role_id == role.id | ||
end | ||
end | ||
variables | ||
end | ||
|
||
def variables_to_s(variables) | ||
str = '' | ||
variables.each do |action, temp_variables| | ||
str += "#{action}: #{temp_variables.size}, " unless temp_variables.empty? | ||
end | ||
str[0..-3] | ||
end | ||
|
||
def get_roles_variables(imported_variables, variables_importer, kind, role) | ||
if kind == 'new' | ||
variables = { 'Add' => variables_importer.get_variables_names(role.name) } | ||
elsif kind == 'obsolete' | ||
variables = { 'Remove' => role.ansible_variables.map(&:key) } | ||
elsif kind == 'old' | ||
variables = get_old_roles_variables(imported_variables, role) | ||
end | ||
variables_to_s(variables) | ||
end | ||
|
||
def prepare_ansible_import_rows(changed, variables_importer) | ||
rows = [] | ||
changed.each do |kind, roles| | ||
imported_variables = variables_importer.import_variable_names(roles) | ||
roles.each do |role| | ||
role_action = get_role_action(kind) | ||
variables = get_roles_variables(imported_variables, variables_importer, kind, role) | ||
next if variables.empty? && kind['old'] | ||
rows.append({ cells: [ | ||
role.name, | ||
role_action, variables, | ||
role_action == 'Remove Role' ? role.hosts.count : '', | ||
role_action == 'Remove Role' ? role.hostgroups.count : '' | ||
], | ||
role: role, kind: kind, id: role.name }) | ||
end | ||
end | ||
rows | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,11 @@ | ||
<% title _("Changed Ansible roles") %> | ||
<%= form_tag confirm_import_ansible_roles_path do %> | ||
<h4><%= _("Select the changes you want to realize in Foreman") %></h4> | ||
<h6> | ||
<%= _("Toggle") %>: | ||
<%= link_to_function(icon_text("check", _("New")), | ||
"toggleCheckboxesBySelector('.role_select_boxes_new')", | ||
:title => _("Check/Uncheck new")) %> | | ||
<%= link_to_function(icon_text("check", _("Obsolete")), | ||
"toggleCheckboxesBySelector('.role_select_boxes_obsolete')", | ||
:title => _("Check/Uncheck obsolete")) %> | ||
</h6> | ||
<table class="<%= table_css_classes %>"> | ||
<thead> | ||
<tr> | ||
<th class="ca"> | ||
<%= link_to_function(icon_text("check"), | ||
"toggleCheckboxesBySelector('.role_select_boxes')", | ||
:title => _("Check/Uncheck all")) %> | ||
</th> | ||
<th><%= _("Name") %></th> | ||
<th class="col-md-2"><%= _("Hosts count") %></th> | ||
<th class="col-md-2"><%= _("Hostgroups count") %></th> | ||
<th><%= _("Operation") %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% changed.each do |kind, roles| %> | ||
<% roles.each do |role| %> | ||
<tr> | ||
<td> | ||
<%= check_box_tag "changed[#{kind}][#{role}]", role.to_json, false, :class => "role_select_boxes role_select_boxes_#{kind} role_select_boxes_role_#{role}" %> | ||
</td> | ||
<td> | ||
<%= link_to_function("#{role}", "toggleCheckboxesBySelector('.role_select_boxes_role_#{role}')", :title => _("Check/Uncheck all %s changes") % role) %> | ||
</td> | ||
<td><%= role.hosts.count %></td> | ||
<td><%= role.hostgroups.count %></td> | ||
<td> | ||
<%= { "new" => _("Add"), "obsolete" => _("Remove") }[kind] %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<div> | ||
<%= link_to _("Cancel"), ansible_roles_path, :class => "btn btn-default" %> | ||
<%= submit_tag _("Update"), :class => "btn btn-primary" %> | ||
</div> | ||
<% end %> | ||
<%= webpacked_plugins_js_for :foreman_ansible %> | ||
<%= webpacked_plugins_css_for :foreman_ansible %> | ||
|
||
|
||
<%= react_component( | ||
'WrappedImportRolesAndVariables', | ||
:rowsData => @rows, | ||
:proxy => @proxy.id | ||
) %> | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.