class Appforce::Spawn::Runner
Constants
- MINIMUM_ANSIBLE_VERSION
Public Class Methods
ansible_ping()
click to toggle source
# 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?()
click to toggle source
# 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_dependencies()
click to toggle source
# 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_command()
click to toggle source
# 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_command()
click to toggle source
# 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_dryrun()
click to toggle source
# 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_playbook()
click to toggle source
# 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
Private Class Methods
ansible_command()
click to toggle source
# File lib/appforce/spawn/runner.rb, line 103 def self.ansible_command # ansible-playbook -i hosts site.yml --extra-vars="ansible_user={{ ansible_user }} users_file=./users.yml" begin vars = YAML::load(File.open('./vars.yml')) rescue Exception => e logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::Spawn::Runner::VarsFileError"\ " -- 'vars.yml' file appears to be malformed -- #{e}" raise e end if vars['ansible_private_key'] "ansible-playbook -i hosts site.yml --private-key=./private_key.pem --extra-vars='ansible_user=#{vars['ansible_user']} active_users_file=./active_users.yml inactive_users_file=./inactive_users.yml'" else "ansible-playbook -i hosts site.yml --extra-vars='ansible_user=#{vars['ansible_user']} active_users_file=./active_users.yml inactive_users_file=./inactive_users.yml'" end end
ansible_installed?()
click to toggle source
# File lib/appforce/spawn/runner.rb, line 86 def self.ansible_installed? ansible = `which ansible` /ansible$/.match(ansible) end
ansible_ping_command()
click to toggle source
# File lib/appforce/spawn/runner.rb, line 120 def self.ansible_ping_command # ansible all -m ping -i hosts -u ansible begin vars = YAML::load(File.open('./vars.yml')) rescue Exception => e logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::Spawn::Runner::VarsFileError"\ " -- 'vars.yml' file appears to be malformed -- #{e}" raise e end if vars['ansible_private_key'] "ansible all -m ping -i hosts --private-key=./private_key.pem -u #{vars['ansible_user']}" else "ansible all -m ping -i hosts -u #{vars['ansible_user']}" end end
good_ansible_version?()
click to toggle source
# File lib/appforce/spawn/runner.rb, line 91 def self.good_ansible_version? str = `ansible --version` version_str = /^ansible\s(\d+\.\d+\.\d+)$/.match(str)[1].tr('.','') return true if version_str.to_i >= MINIMUM_ANSIBLE_VERSION.tr('.','').to_i nil end
logger()
click to toggle source
# File lib/appforce/spawn/runner.rb, line 137 def self.logger Appforce::Logger.logger end
rvm_galaxy_installed?()
click to toggle source
# File lib/appforce/spawn/runner.rb, line 98 def self.rvm_galaxy_installed? galaxy = `ansible-galaxy list` /^-\srvm_io.rvm1-ruby,\sv1\.3/.match(galaxy) end