Class: ForemanAnsible::ApiRolesImporter
- Inherits:
-
RolesImporter
- Object
- RolesImporter
- ForemanAnsible::ApiRolesImporter
- Includes:
- AnsibleRolesDataPreparations
- Defined in:
- app/services/foreman_ansible/api_roles_importer.rb
Overview
imports Ansible roles through API
Constant Summary
Constants included from AnsibleRolesDataPreparations
ForemanAnsible::AnsibleRolesDataPreparations::ROLE_ACTION_NAMES, ForemanAnsible::AnsibleRolesDataPreparations::VARIABLE_ACTION_NAMES
Instance Method Summary collapse
- #confirm_import(params) ⇒ Object
- #confirm_sync(params) ⇒ Object
- #import!(role_names) ⇒ Object
- #obsolete! ⇒ Object
Methods included from AnsibleRolesDataPreparations
#excluded_roles, #get_old_roles_variables, #get_roles_variables, #prepare_ansible_import_rows, #prepare_api_row, #prepare_ui_row, #role_action_name, #role_match_excluded_roles, #variable_action_name, #variables_to_s
Methods inherited from RolesImporter
#detect_changes, #fetch_role_names, #import_role_names, #import_roles, #initialize
Constructor Details
This class inherits a constructor from ForemanAnsible::RolesImporter
Instance Method Details
#confirm_import(params) ⇒ Object
22 23 24 25 |
# File 'app/services/foreman_ansible/api_roles_importer.rb', line 22 def confirm_import(params) @roles_importer.finish_import(params['changed']) @variables_importer.import_variables_roles(params['changed']) if params['changed']['new'] || params['changed']['old'] end |
#confirm_sync(params) ⇒ Object
27 28 29 30 31 |
# File 'app/services/foreman_ansible/api_roles_importer.rb', line 27 def confirm_sync(params) job = SyncRolesAndVariables.perform_later(params['changed'], @ansible_proxy) task = ForemanTasks::Task.find_by(external_id: job.provider_job_id) task end |
#import!(role_names) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/services/foreman_ansible/api_roles_importer.rb', line 8 def import!(role_names) @roles_importer = ForemanAnsible::UiRolesImporter.new(@ansible_proxy) @variables_importer = ForemanAnsible::VariablesImporter.new(@ansible_proxy) params = { 'changed' => {} } roles = prepare_ansible_import_rows(@roles_importer.import!, @variables_importer, false) roles.each do |role| if role_names.include? role[:name] params['changed'][role[:kind]] ||= {} params['changed'][role[:kind]][role[:name]] = { 'id' => role[:id], 'name' => role[:name] } end end params end |
#obsolete! ⇒ Object
33 34 35 36 37 |
# File 'app/services/foreman_ansible/api_roles_importer.rb', line 33 def obsolete! obsolete_roles = import_role_names[:obsolete] obsolete_roles.map(&:destroy) obsolete_roles end |