class ForemanAnsibleCore::CommandCreator

Creates the actual command to be passed to foreman_tasks_core to run

Attributes

command[R]

Public Class Methods

new(inventory_file, playbook_file, options = {}) click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 6
def initialize(inventory_file, playbook_file, options = {})
  @options = options
  @command = [{ 'JSON_INVENTORY_FILE' => inventory_file }]
  @command << 'ansible-playbook'
  @command = command_options(@command)
  @command << playbook_file
end

Private Instance Methods

command_options(command) click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 16
def command_options(command)
  command.concat(['-i', json_inventory_script])
  command.concat([setup_verbosity]) if verbose?
  command.concat(['-T', @options[:timeout]]) unless @options[:timeout].nil?
  command
end
json_inventory_script() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 23
def json_inventory_script
  File.expand_path('../../bin/json_inventory.sh', File.dirname(__FILE__))
end
setup_verbosity() click to toggle source
# File lib/foreman_ansible_core/command_creator.rb, line 27
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 36
def verbose?
  verbosity_level = @options[:verbosity_level]
  # rubocop:disable Rails/Present
  !verbosity_level.nil? && !verbosity_level.empty? &&
    verbosity_level.to_i > 0
  # rubocop:enable Rails/Present
end