Class: Appforce::Spawn::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/appforce/spawn/runner.rb

Constant Summary collapse

MINIMUM_ANSIBLE_VERSION =
"1.8.3"

Class Method Summary collapse

Class Method Details

.ansible_pingObject



26
27
28
29
30
31
# File 'lib/appforce/spawn/runner.rb', line 26

def self.ansible_ping
  logger.info "[#{self.name}##{__method__.to_s}] Start running ansible ping."
  logger.debug "[#{self.name}##{__method__.to_s}] ansible_ping_command: #{ansible_ping_command} --check --diff"
  system "#{ansible_ping_command}"
  logger.info "[#{self.name}##{__method__.to_s}] Ansible ping complete."
end

.can_run?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/appforce/spawn/runner.rb', line 37

def self.can_run?
  # validate stuff first
  check_dependencies
  unless File.exist?('./vars.yml')
    logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'vars.yml' file"
    raise Appforce::Spawn::MissingFile, "Missing 'vars.yml' file"
  end
  unless File.exist?('./hosts')
    logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'hosts' file"
    raise Appforce::Spawn::MissingFile, "Missing 'hosts' file"
  end
  unless File.exist?('./active_users.yml')
    logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'active_users.yml' file"
    raise Appforce::Spawn::MissingFile, "Missing 'active_users.yml' file"
  end
  unless File.exist?('./inactive_users.yml')
    logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingFile -- Missing 'inactive_users.yml' file"
    raise Appforce::Spawn::MissingFile, "Missing 'inactive_users.yml' file"
  end
  true
end

.check_dependenciesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/appforce/spawn/runner.rb', line 59

def self.check_dependencies
  # ansible install
  unless ansible_installed?
    logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Missing 'ansible' executable."
    raise Appforce::Spawn::Dependency, "Missing 'ansible' executable"
  end

  # ansible version
  unless good_ansible_version?
    str = `ansible --version`
    version_str = /^ansible\s(\d+\.\d+\.\d+)$/.match(str)[1].tr('.','')
    logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Insufficient 'ansible' version: #{version_str} < #{MINIMUM_ANSIBLE_VERSION}"
    raise Appforce::Spawn::Dependency, "Insufficient 'ansible' version: #{version_str} < #{MINIMUM_ANSIBLE_VERSION}"
  end

  # ansible rvm_io.rvm1-ruby galaxy install
  unless rvm_galaxy_installed?
    logger.error "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Missing 'rvm_io.rvm1-ruby' galaxy role."
    logger.info "[#{self.name}##{__method__.to_s}] Appforce::Spawn::MissingDependency -- Run 'ansible-galaxy install rvm_io.rvm1-ruby' to install role"
    raise Appforce::Spawn::Dependency, "Missing 'rvm_io.rvm1-ruby' galaxy role"
  end

  true
end

.display_ansible_commandObject



22
23
24
# File 'lib/appforce/spawn/runner.rb', line 22

def self.display_ansible_command
  logger.info "[#{self.name}##{__method__.to_s}] Ansible command to run playbook for this Client is:\n -- #{ansible_command}"
end

.display_ansible_ping_commandObject



33
34
35
# File 'lib/appforce/spawn/runner.rb', line 33

def self.display_ansible_ping_command
  logger.info "[#{self.name}##{__method__.to_s}] Ansible command to ping this Client is:\n -- #{ansible_ping_command}"
end

.run_dryrunObject



15
16
17
18
19
20
# File 'lib/appforce/spawn/runner.rb', line 15

def self.run_dryrun
  logger.info "[#{self.name}##{__method__.to_s}] Start running dry-run of playbook."
  logger.debug "[#{self.name}##{__method__.to_s}] ansible_dryrun_command: #{ansible_command} --check --diff"
  system "#{ansible_command} --check --diff"
  logger.info "[#{self.name}##{__method__.to_s}] Playbook dry-run complete."
end

.run_playbookObject



8
9
10
11
12
13
# File 'lib/appforce/spawn/runner.rb', line 8

def self.run_playbook
  logger.info "[#{self.name}##{__method__.to_s}] Start running playbook."
  logger.debug "[#{self.name}##{__method__.to_s}] ansible_command: #{ansible_command}"
  system "#{ansible_command}"
  logger.info "[#{self.name}##{__method__.to_s}] Playbook run complete."
end