module Powerplay::Play::Ansible
Constants
- OPTS
- PLAYBOOK
Public Class Methods
get_book_apcmd(book, bucher, grouppe)
click to toggle source
# File lib/ansible-powerplay/powerplay.rb, line 99 def self.get_book_apcmd(book, bucher, grouppe) dryrun = Play::clopts[:dryrun] extra = Play::clopts[:extra] tags = Play::clopts[:tags] sktags = Play::clopts[:sktags] tmuxout, tmuxpanes = Play::clopts[:tmux] apverb = Play::clopts[:apverbose] verb = (apverb == 0) ? '' : ('-' + ('v' * apverb)) tagstr = '' if tags and sktags puts "Cannot use both --tags (#{tags}) and --skip-tags (#{sktags})" exit 5 end tagstr += %( --tags "#{tags}" ) unless tags.nil? tagstr += %( --skip-tags "#{sktags}" ) unless sktags.nil? tty ||= Tmux.grab_a_tty puts " tty == #{tty} (#{Tmux.pane_ttys.values.last})" unless DSL::_verbosity < 2 if (book.type != :noop) and (bucher.first == :all or bucher.member?(book.type)) and (grouppe.first == :all or not (grouppe & book.family).empty?) puts " BOOK #{book.type}" inv = if book.config.member? :inventory "-i #{book.config[:inventory].first}" else '' end xxv = [extra[book.type], extra[:all]].compact.join(' ') # a=b c=d ... redirect = (tmuxout.nil?) ? '' : " > #{tty}" apcmd = %|#{PLAYBOOK} #{OPTS} #{inv} #{book.config[:playbook_directory].first}/#{book.yaml} #{tagstr} --extra-vars '#{book.aparams(xxv)}' #{verb} #{redirect}| unless DSL::_verbosity < 1 puts "==============================".green puts "Running #{book.plan} book ".light_yellow + ":#{book.type}".light_cyan + " group heirarchy [".light_yellow + "#{book.family.map{|g| ':' + g.to_s}.join(' < ')}".light_cyan + "]".light_yellow puts "\n#{apcmd}".yellow puts "------------------------------" end (dryrun) ? nil : apcmd else nil end end
groups(playbook) { |group| ... }
click to toggle source
deprecated
# File lib/ansible-powerplay/powerplay.rb, line 82 def self.groups(playbook) grps = Play::clopts[:group].map{ |g| g.to_sym} playbook.groups.each do |group| yield group if grps.first == :all or grps.member?(group.type) end end
jobs()
click to toggle source
# File lib/ansible-powerplay/powerplay.rb, line 89 def self.jobs @jobs ||= [] end
join_jobs()
click to toggle source
# File lib/ansible-powerplay/powerplay.rb, line 93 def self.join_jobs while not jobs.empty? jobs.shift.join end end
playbooks() { |pplay, group| ... }
click to toggle source
deprecated
# File lib/ansible-powerplay/powerplay.rb, line 74 def self.playbooks plays = Play::clopts[:play].map{ |y| y.to_sym } DSL::_global[:playbooks].each do |pplay, group| yield pplay, group if plays.first == :all or plays.member? pplay end end
power_run()
click to toggle source
Will remove entries from the planning queue in FIFO fashion, and execution them according to the algorithm as described in the README.org, Implementation of the Execution Planning, which is considered “authoritative” on how power_run
works.
# File lib/ansible-powerplay/powerplay.rb, line 150 def self.power_run bucher = Play::clopts[:book].map{ |b| b.to_sym } grouppe = Play::clopts[:group].map{ |b| b.to_sym } errors = [] # old-style looping, alas while DSL::_peek book = DSL::_dequeue apcmd = get_book_apcmd book, bucher, grouppe join_jobs if book.plan == :sync j = unless apcmd.nil? Thread.new(book, apcmd) { |bk, cmd| std, status = Open3.capture2e cmd puts "**** Playbook #{bk.yaml} ****".light_blue, std if status.success? errors << [bk.yaml, cmd, std, status] unless status.success? } else nil end if book.plan == :sync puts "Sync execution of :#{book.type} => #{book.yaml}".light_magenta unless DSL::_verbosity < 2 j.join unless j.nil? elsif book.plan == :async puts "ASync execution of :#{book.type} => #{book.yaml}".magenta unless DSL::_verbosity < 2 jobs << j unless j.nil? else raise "Book plan error #{book.plan} for book #{book.type}" end end # finish the lot and report on any errors join_jobs unless errors.empty? errors.each do |yaml, cmd, txt, status| puts ('=' * 60).light_red puts (('*' * 10) + ' ' + yaml).light_red + " exit status #{status.exitstatus}".light_blue puts txt.light_yellow puts ('-' * 30).red puts cmd.red end exit 10 end end