class ForemanAnsibleCore::CommandCreator

Creates the actual command to be passed to foreman_tasks_core to run

Public Class Methods

new(inventory_file, playbook_file, options = {}) click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 5
def initialize(inventory_file, playbook_file, options = {})
  @options = options
  @playbook_file = playbook_file
  @inventory_file = inventory_file
  command
end

Public Instance Methods

command() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 12
def command
  parts = [environment_variables]
  parts << 'ansible-playbook'
  parts.concat(command_options)
  parts << @playbook_file
  parts
end

Private Instance Methods

command_options() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 28
def command_options
  opts = ['-i', json_inventory_script]
  opts.concat([setup_verbosity]) if verbose?
  opts.concat(['-T', @options[:timeout]]) unless @options[:timeout].nil?
  opts
end
environment_variables() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 22
def environment_variables
  defaults = { 'JSON_INVENTORY_FILE' => @inventory_file }
  defaults['ANSIBLE_CALLBACK_WHITELIST'] = '' if rex_command?
  defaults
end
json_inventory_script() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 35
def json_inventory_script
  File.expand_path('../../bin/json_inventory.sh', File.dirname(__FILE__))
end
rex_command?() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 56
def rex_command?
  @options[:remote_execution_command]
end
setup_verbosity() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 39
def setup_verbosity
  verbosity_level = @options[:verbosity_level].to_i
  verbosity = '-'
  verbosity_level.times do
    verbosity += 'v'
  end
  verbosity
end
verbose?() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 48
def verbose?
  verbosity_level = @options[:verbosity_level]
  # rubocop:disable Rails/Present
  !verbosity_level.nil? && !verbosity_level.empty? &&
    verbosity_level.to_i.positive?
  # rubocop:enable Rails/Present
end