Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #32409 - Use new DSL to define settings #448

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/api/v2/ansible_inventories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def action_permission
private

def schedule_params
template_name = Setting::Ansible.find_by(:name => 'ansible_inventory_template').value
template_name = Setting['ansible_inventory_template']
@report_template = ReportTemplate.find_by!(:name => template_name)
params[:id] = @report_template.id
params[:report_format] = 'json' if params[:report_format].blank?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def play_ansible_roles
composer.triggering.mode = :future
composer.triggering.start_at = (
Time.zone.now +
Setting::Ansible[:ansible_post_provision_timeout].to_i.seconds
Setting[:ansible_post_provision_timeout].to_i.seconds
)
composer.trigger!
logger.info("Task for Ansible roles on #{self} before_provision: "\
Expand Down
106 changes: 0 additions & 106 deletions app/models/setting/ansible.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FixAnsibleSettingCategoryToDsl < ActiveRecord::Migration[6.0]
def up
Setting.where(category: 'Setting::Ansible').update_all(category: 'Setting')
end
end
6 changes: 0 additions & 6 deletions lib/foreman_ansible/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ class Engine < ::Rails::Engine
config.autoload_paths += Dir["#{config.root}/app/views"]
config.autoload_paths += Dir["#{config.root}/app/lib"]

initializer 'foreman_ansible.load_default_settings',
:before => :load_config_initializers do
require_dependency(File.join(ForemanAnsible::Engine.root,
'app/models/setting/ansible.rb'))
end

initializer 'foreman_ansible.register_gettext',
:after => :load_config_initializers do
locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
Expand Down
75 changes: 75 additions & 0 deletions lib/foreman_ansible/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,81 @@
Foreman::Plugin.register :foreman_ansible do
requires_foreman '>= 2.6'

settings do
category :ansible, N_('Ansible') do
setting 'ansible_ssh_private_key_file',
adiabramovitch marked this conversation as resolved.
Show resolved Hide resolved
type: :string,
description: N_('Use this to supply a path to an SSH Private Key '\
'that Ansible will use in lieu of a password '\
'Override with "ansible_ssh_private_key_file" '\
'host parameter'),
default: '',
full_name: N_('Private Key Path')
setting 'ansible_connection',
type: :string,
description: N_('Use this connection type by default when running '\
'Ansible playbooks. You can override this on hosts by '\
'adding a parameter "ansible_connection"'),
default: 'ssh',
full_name: N_('Connection type')
setting 'ansible_winrm_server_cert_validation',
type: :string,
description: N_('Enable/disable WinRM server certificate '\
'validation when running Ansible playbooks. You can override '\
'this on hosts by adding a parameter '\
'"ansible_winrm_server_cert_validation"'),
default: 'validate',
full_name: N_('WinRM cert Validation')
setting 'ansible_verbosity',
type: :integer,
description: N_('Foreman will add this level of verbosity for '\
'additional debugging output when running Ansible playbooks.'),
default: '0',
full_name: N_('Default verbosity level'),
value: nil,
collection: proc {
{ '0' => N_('Disabled'),
'1' => N_('Level 1 (-v)'),
'2' => N_('Level 2 (-vv)'),
'3' => N_('Level 3 (-vvv)'),
'4' => N_('Level 4 (-vvvv)') }
}
setting 'ansible_post_provision_timeout',
type: :integer,
description: N_('Timeout (in seconds) to set when Foreman will trigger a '\
'play Ansible roles task after a host is fully provisioned. '\
'Set this to the maximum time you expect a host to take '\
'until it is ready after a reboot.'),
default: '360',
full_name: N_('Post-provision timeout')
setting 'ansible_interval',
type: :integer,
description: N_('Timeout (in minutes) when hosts should have reported.'),
default: '30',
full_name: N_('Ansible report timeout')
setting 'ansible_out_of_sync_disabled',
type: :boolean,
description: format(N_('Disable host configuration status turning to out of'\
' sync for %{cfgmgmt} after report does not arrive within'\
' configured interval'), :cfgmgmt => 'Ansible'),
default: false,
full_name: format(N_('%{cfgmgmt} out of sync disabled'), :cfgmgmt => 'Ansible')
setting 'ansible_inventory_template',
type: :string,
description: N_('Foreman will use this template to schedule the report '\
'with Ansible inventory'),
default: 'Ansible - Ansible Inventory',
full_name: N_('Default Ansible inventory report template')
setting 'ansible_roles_to_ignore',
type: :array,
description: N_('Those roles will be excluded when importing roles from smart proxy, '\
'The expected input is comma separated values and you can use * wildcard metacharacters'\
'For example: foo*, *b*,*bar'),
default: [],
full_name: N_('Ansible roles to ignore')
end
end

security_block :foreman_ansible do
permission :play_roles_on_host,
{ :hosts => [:play_roles, :multiple_play_roles],
Expand Down