Skip to content

Commit

Permalink
Fixes #32814 - Fix working dir when doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
adiabramovitch committed Nov 21, 2021
1 parent d5790d2 commit 7cb6a1b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/smart_proxy_ansible.rb
Expand Up @@ -4,6 +4,8 @@ module Proxy
# Basic requires for this plugin
module Ansible
require 'smart_proxy_ansible/version'
require 'smart_proxy_ansible/configuration_loader'
require 'smart_proxy_ansible/validate_settings'
require 'smart_proxy_ansible/plugin'
require 'smart_proxy_ansible/roles_reader'
require 'smart_proxy_ansible/variables_extractor'
Expand Down
20 changes: 20 additions & 0 deletions lib/smart_proxy_ansible/configuration_loader.rb
@@ -0,0 +1,20 @@
module Proxy::Ansible
class ConfigurationLoader
def load_classes
require 'smart_proxy_dynflow'
require 'smart_proxy_dynflow/continuous_output'
require 'smart_proxy_ansible/task_launcher/ansible_runner'
require 'smart_proxy_ansible/task_launcher/playbook'
require 'smart_proxy_ansible/actions'
require 'smart_proxy_ansible/remote_execution_core/ansible_runner'
require 'smart_proxy_ansible/runner/ansible_runner'
require 'smart_proxy_ansible/runner/command_creator'
require 'smart_proxy_ansible/runner/playbook'

Proxy::Dynflow::TaskLauncherRegistry.register('ansible-runner',
TaskLauncher::AnsibleRunner)
Proxy::Dynflow::TaskLauncherRegistry.register('ansible-playbook',
TaskLauncher::Playbook)
end
end
end
1 change: 1 addition & 0 deletions lib/smart_proxy_ansible/exception.rb
Expand Up @@ -37,5 +37,6 @@ def to_s
class ReadConfigFileException < Proxy::Ansible::Exception; end
class ReadRolesException < Proxy::Ansible::Exception; end
class ReadVariablesException < Proxy::Ansible::Exception; end
class NotExistingWorkingDirException < Proxy::Ansible::Exception; end
end
end
19 changes: 3 additions & 16 deletions lib/smart_proxy_ansible/plugin.rb
Expand Up @@ -8,22 +8,9 @@ class Plugin < Proxy::Plugin
default_settings :ansible_dir => Dir.home
# :working_dir => nil

after_activation do
require 'smart_proxy_dynflow'
require 'smart_proxy_dynflow/continuous_output'
require 'smart_proxy_ansible/task_launcher/ansible_runner'
require 'smart_proxy_ansible/task_launcher/playbook'
require 'smart_proxy_ansible/actions'
require 'smart_proxy_ansible/remote_execution_core/ansible_runner'
require 'smart_proxy_ansible/runner/ansible_runner'
require 'smart_proxy_ansible/runner/command_creator'
require 'smart_proxy_ansible/runner/playbook'

Proxy::Dynflow::TaskLauncherRegistry.register('ansible-runner',
TaskLauncher::AnsibleRunner)
Proxy::Dynflow::TaskLauncherRegistry.register('ansible-playbook',
TaskLauncher::Playbook)
end
load_classes ::Proxy::Ansible::ConfigurationLoader
load_validators :validate_settings => ::Proxy::Ansible::ValidateSettings
validate :validate!, :validate_settings => nil
end
end
end
7 changes: 7 additions & 0 deletions lib/smart_proxy_ansible/validate_settings.rb
@@ -0,0 +1,7 @@
module Proxy::Ansible
class ValidateSettings < ::Proxy::PluginValidators::Base
def validate!(settings)
raise NotExistingWorkingDirException.new("Working directory does not exist") unless File.expand_path(settings[:working_dir]).nil? || File.directory?(File.expand_path(settings[:working_dir]))
end
end
end

0 comments on commit 7cb6a1b

Please sign in to comment.