ansible-powerplay 0.2.4 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,6 @@ module Powerplay
10
10
  end
11
11
 
12
12
  module Tmux
13
-
14
13
  def self.current_tty
15
14
  %x[tty].chop
16
15
  end
@@ -53,14 +52,15 @@ module Powerplay
53
52
  PLAYBOOK = "ansible-playbook"
54
53
  OPTS = ""
55
54
 
55
+ # deprecated
56
56
  def self.playbooks
57
57
  plays = Play::clopts[:play].map{ |y| y.to_sym }
58
58
  DSL::_global[:playbooks].each do |pplay, group|
59
59
  yield pplay, group if plays.first == :all or plays.member? pplay
60
60
  end
61
61
  end
62
-
63
- # groups are serial
62
+
63
+ # deprecated
64
64
  def self.groups(playbook)
65
65
  grps = Play::clopts[:group].map{ |g| g.to_sym}
66
66
  playbook.groups.each do |group|
@@ -68,11 +68,22 @@ module Powerplay
68
68
  end
69
69
  end
70
70
 
71
- def self.run_book(book, bucher, book_threads, errors)
72
- dryrun = Play::clopts[:dryrun]
73
- extra = Play::clopts[:extra]
74
- tags = Play::clopts[:tags]
75
- sktags = Play::clopts[:sktags]
71
+ def self.jobs
72
+ @jobs ||= []
73
+ end
74
+
75
+ def self.join_jobs
76
+ while not jobs.empty?
77
+ jobs.shift.join
78
+ end
79
+ end
80
+
81
+ def self.get_book_apcmd(book, bucher, grouppe)
82
+ dryrun = Play::clopts[:dryrun]
83
+ extra = Play::clopts[:extra]
84
+ tags = Play::clopts[:tags]
85
+ sktags = Play::clopts[:sktags]
86
+ tmuxout = Play::clopts[:tmux]
76
87
  tagstr = ''
77
88
  if tags and sktags
78
89
  puts "Cannot use both --tags (#{tags}) and --skip-tags (#{sktags})"
@@ -82,7 +93,9 @@ module Powerplay
82
93
  tagstr += %( --skip-tags "#{sktags}" ) unless sktags.nil?
83
94
  tty ||= Tmux.grab_a_tty
84
95
  puts " tty == #{tty} (#{Tmux.pane_ttys.last})" unless DSL::_verbosity < 2
85
- if bucher.first == :all or bucher.member?(book.type)
96
+ if (book.type != :noop) and
97
+ (bucher.first == :all or bucher.member?(book.type)) and
98
+ (grouppe.first == :all or not (grouppe & book.family).empty?)
86
99
  puts " BOOK #{book.type}"
87
100
  inv = if book.config.member? :inventory
88
101
  "-i #{book.config[:inventory].first}"
@@ -90,48 +103,70 @@ module Powerplay
90
103
  ''
91
104
  end
92
105
  xxv = [extra[book.type], extra[:all]].compact.join(' ')
93
- apcmd = %|#{PLAYBOOK} #{OPTS} #{inv} #{book.config[:playbook_directory].first}/#{book.yaml} #{tagstr} --extra-vars "#{book.aparams} #{xxv}" >#{tty}|
106
+ redirect = (tmuxout.nil?) ? '' : " > #{tty}"
107
+ apcmd = %|#{PLAYBOOK} #{OPTS} #{inv} #{book.config[:playbook_directory].first}/#{book.yaml} #{tagstr} --extra-vars "#{book.aparams} #{xxv}" #{redirect}|
94
108
  unless DSL::_verbosity < 1
95
- puts "==============================\nRunning command:"
96
- puts "#{apcmd}".yellow
109
+ puts "==============================".green
110
+ puts "Running #{book.plan} book ".light_yellow +
111
+ ":#{book.type}".light_cyan +
112
+ " group heirarchy [".light_yellow +
113
+ "#{book.family.map{|g| ':' + g.to_s}.join(' < ')}".light_cyan +
114
+ "]".light_yellow
115
+ puts "\n#{apcmd}".yellow
97
116
  puts "------------------------------"
98
117
  end
99
- book_threads << Thread.new {
100
- std, status = Open3.capture2e apcmd
101
- errors << [book.yaml, apcmd, std] unless status.success?
102
- } unless dryrun
118
+ (dryrun) ? nil : apcmd
119
+ else
120
+ nil
103
121
  end
104
122
  end
105
123
 
124
+ # Will remove entries from the planning queue in FIFO
125
+ # fashion, and execution them according to the algorithm
126
+ # as described in the README.org, Implementation of
127
+ # the Execution Planning, which is considered "authoritative"
128
+ # on how power_run works.
106
129
  def self.power_run
107
130
  bucher = Play::clopts[:book].map{ |b| b.to_sym }
108
- congroups = Play::clopts[:congroups]
109
- playbooks do |pname, playbook|
110
- group_threads = []
111
- puts "PLAYBOOK #{pname} (group=#{Play::clopts[:group]}) -->"
112
- groups playbook do |group|
113
- tg = nil
114
- group_threads << (tg = Thread.new {
115
- puts " GROUP #{group.type} (book=#{bucher}, cg=#{congroups}) -->"
116
- book_threads = []
117
- errors = []
118
- group.books.each { |book| run_book(book, bucher, book_threads, errors) }
119
- book_threads.each{ |t| t.join }
120
- unless errors.empty?
121
- errors.each do |yaml, cmd, txt|
122
- puts '=' * 30
123
- puts ('*' * 10) + ' ' + yaml
124
- puts txt
125
- puts '-' * 30
126
- puts cmd
127
- end
128
- exit 10
129
- end
130
- })
131
- # Always wait here unless we're concurrent
132
- group_threads.join unless congroups
131
+ grouppe = Play::clopts[:group].map{ |b| b.to_sym }
132
+ errors = []
133
+
134
+ # old-style looping, alas
135
+ while DSL::_peek
136
+ book = DSL::_dequeue
137
+ apcmd = get_book_apcmd book, bucher, grouppe
138
+ join_jobs if book.plan == :sync
139
+ j = unless apcmd.nil?
140
+ Thread.new(book, apcmd) { |bk, cmd|
141
+ std, status = Open3.capture2e cmd
142
+ puts "**** Playbook #{bk.yaml} ****".light_blue, std if status.success?
143
+ errors << [bk.yaml, cmd, std, status] unless status.success?
144
+ }
145
+ else
146
+ nil
147
+ end
148
+ if book.plan == :sync
149
+ puts "Sync execution of :#{book.type} => #{book.yaml}".light_magenta unless DSL::_verbosity < 2
150
+ j.join unless j.nil?
151
+ elsif book.plan == :async
152
+ puts "ASync execution of :#{book.type} => #{book.yaml}".magenta unless DSL::_verbosity < 2
153
+ jobs << j unless j.nil?
154
+ else
155
+ raise "Book plan error #{book.plan} for book #{book.type}"
156
+ end
157
+ end
158
+
159
+ # finish the lot and report on any errors
160
+ join_jobs
161
+ unless errors.empty?
162
+ errors.each do |yaml, cmd, txt, status|
163
+ puts ('=' * 60).light_red
164
+ puts (('*' * 10) + ' ' + yaml).light_red + " exit status #{status.exitstatus}".light_blue
165
+ puts txt.light_yellow
166
+ puts ('-' * 30).red
167
+ puts cmd.red
133
168
  end
134
- group_threads.each{ |t| t.join }
169
+ exit 10
135
170
  end
136
171
  end
137
172
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible-powerplay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-25 00:00:00.000000000 Z
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -25,35 +25,49 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: concurrent-ruby
28
+ name: term-ansicolor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: term-ansicolor
42
+ name: colorize
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: colorize
56
+ name: semver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: queue_ding
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: semver
84
+ name: concurrent-ruby
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
@@ -284,6 +298,7 @@ description: |-
284
298
  email: fred.mitchell@gmx.de
285
299
  executables:
286
300
  - powerplay
301
+ - pp
287
302
  extensions: []
288
303
  extra_rdoc_files:
289
304
  - LICENSE.txt
@@ -302,6 +317,14 @@ files:
302
317
  - SCRATCHPAD.org
303
318
  - ansible-powerplay.gemspec
304
319
  - bin/powerplay
320
+ - bin/pp
321
+ - examples/playbooks/dat.yml
322
+ - examples/playbooks/elasticseach.yml
323
+ - examples/playbooks/first.yml
324
+ - examples/playbooks/nat.yml
325
+ - examples/playbooks/rabbitmq.yml
326
+ - examples/playbooks/rat.yml
327
+ - examples/playbooks/second.yml
305
328
  - lib/ansible-powerplay.rb
306
329
  - lib/ansible-powerplay/cli.rb
307
330
  - lib/ansible-powerplay/dsl.rb