pero 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecfeedf1f5589503f81308e4df7f4e8ce6735d17ea53aa146b9a6ff4749b65c6
4
- data.tar.gz: 6ae0544b2f34d3d8f26ef8c1d10338528091215cf4ae3e7620c0d86829a6ed2d
3
+ metadata.gz: 987ee0dddd45d8f05e4a1ca60cfe2df83a31542e2793931ddfda01446f3bbe1b
4
+ data.tar.gz: 791d656dc30d9530316a10fa5b7dc08c69e7089d24a5b040f884435a44f4f038
5
5
  SHA512:
6
- metadata.gz: fc3aad015bc517fbedcb5aa30ea824cbc08819c63054e09491d389ff2383119ab3449b895a5d8caf17450271dc7398d474159050006c590bfb6a71130f8c5d43
7
- data.tar.gz: 06ea7ee5a816e62bb257636c53c863709e3217e7d6fe218bec9efdb51ccee4821d4ff3013c79528ce2813f693c081e090d295393c8b68fc35d504083e6d2b461
6
+ metadata.gz: 1745f07c1634fc170bd6b34c5f2332627a86d2352645045919cdd26e5cf57a3b6bb32e69606b2be4f7dbc6272153905f36095699062a89d047c2e1e54dacd330
7
+ data.tar.gz: e866274608d76736a53f74f0d9e2b0503c55e200548b1df204059743daca66c7cb208ff387cd9ffcd9bbe170fbd6cc7beb433822ffd55b4c4809104982b537a4
data/lib/pero/puppet.rb CHANGED
@@ -9,9 +9,9 @@ module Specinfra
9
9
  return @sudo_password if defined?(@sudo_password)
10
10
 
11
11
  # TODO: Fix this dirty hack
12
- return nil unless caller.any? {|call| call.include?('channel_data') }
12
+ return nil unless caller.any? { |call| call.include?('channel_data') }
13
13
 
14
- print "sudo password: "
14
+ print 'sudo password: '
15
15
  @sudo_password = STDIN.noecho(&:gets).strip
16
16
  print "\n"
17
17
  @sudo_password
@@ -23,6 +23,7 @@ module Pero
23
23
  class Puppet
24
24
  extend Pero::SshExecutable
25
25
  attr_reader :specinfra
26
+
26
27
  def initialize(host, options, mutex)
27
28
  @options = options.dup
28
29
  @mutex = mutex
@@ -30,15 +31,13 @@ module Pero
30
31
  @options[:host] = host
31
32
  so = ssh_options
32
33
 
33
- if !Net::SSH::VALID_OPTIONS.include?(:strict_host_key_checking)
34
- so.delete(:strict_host_key_checking)
35
- end
34
+ so.delete(:strict_host_key_checking) unless Net::SSH::VALID_OPTIONS.include?(:strict_host_key_checking)
36
35
 
37
36
  @specinfra = Specinfra::Backend::Ssh.new(
38
37
  request_pty: true,
39
38
  host: so[:host_name],
40
39
  ssh_options: so,
41
- disable_sudo: false,
40
+ disable_sudo: false
42
41
  )
43
42
  end
44
43
 
@@ -48,15 +47,15 @@ module Pero
48
47
  opts[:host_name] = @options[:host]
49
48
 
50
49
  # from ssh-config
51
- ssh_config_files = @options["ssh_config"] ? [@options["ssh_config"]] : Net::SSH::Config.default_files
52
- opts.merge!(Net::SSH::Config.for(@options["host"], ssh_config_files))
53
- opts[:user] = @options["user"] || opts[:user] || Etc.getlogin
54
- opts[:password] = @options["password"] if @options["password"]
55
- opts[:keys] = [@options["key"]] if @options["key"]
56
- opts[:port] = @options["port"] if @options["port"]
57
- opts[:timeout] = @options["timeout"] if @options["timeout"]
58
-
59
- if @options["vagrant"]
50
+ ssh_config_files = @options['ssh_config'] ? [@options['ssh_config']] : Net::SSH::Config.default_files
51
+ opts.merge!(Net::SSH::Config.for(@options['host'], ssh_config_files))
52
+ opts[:user] = @options['user'] || opts[:user] || Etc.getlogin
53
+ opts[:password] = @options['password'] if @options['password']
54
+ opts[:keys] = [@options['key']] if @options['key']
55
+ opts[:port] = @options['port'] if @options['port']
56
+ opts[:timeout] = @options['timeout'] if @options['timeout']
57
+
58
+ if @options['vagrant']
60
59
  config = Tempfile.new('', Dir.tmpdir)
61
60
  hostname = opts[:host_name] || 'default'
62
61
  vagrant_cmd = "vagrant ssh-config #{hostname} > #{config.path}"
@@ -70,8 +69,8 @@ module Pero
70
69
  opts.merge!(Net::SSH::Config.for(hostname, [config.path]))
71
70
  end
72
71
 
73
- if @options["ask_password"]
74
- print "password: "
72
+ if @options['ask_password']
73
+ print 'password: '
75
74
  password = STDIN.noecho(&:gets).strip
76
75
  print "\n"
77
76
  opts.merge!(password: password)
@@ -82,47 +81,55 @@ module Pero
82
81
  def install
83
82
  osi = specinfra.os_info
84
83
  os = case osi[:family]
85
- when "redhat"
86
- Redhat.new(specinfra, osi)
87
- else
88
- raise "sorry unsupport os, please pull request!!!"
89
- end
90
- os.install(@options["agent-version"]) if @options["agent-version"]
84
+ when 'redhat'
85
+ Redhat.new(specinfra, osi)
86
+ else
87
+ raise 'sorry unsupport os, please pull request!!!'
88
+ end
89
+ os.install(@options['agent-version']) if @options['agent-version']
91
90
  Pero::History::Attribute.new(specinfra, @options).save
92
91
  end
93
92
 
94
93
  def stop_master
94
+ @mutex.lock
95
95
  run_container.kill if docker.alerady_run?
96
+ ensure
97
+ @mutex.unlock
96
98
  end
97
99
 
98
100
  def serve_master
99
- container = run_container
100
- begin
101
- yield container
102
- rescue => e
103
- Pero.log.error e.inspect
104
- raise e
105
- end
101
+ container = run_container
102
+ begin
103
+ yield container
104
+ rescue StandardError => e
105
+ Pero.log.error e.inspect
106
+ raise e
107
+ end
106
108
  end
107
109
 
108
110
  def docker
109
- Pero::Docker.new(@options["server-version"], @options["image-name"], @options["environment"], @options["volumes"])
111
+ Pero::Docker.new(@options['server-version'], @options['image-name'], @options['environment'], @options['volumes'])
110
112
  end
111
113
 
112
114
  def run_container
113
- begin
114
- @mutex.lock
115
- docker.alerady_run? || docker.run
116
- ensure
117
- @mutex.unlock
118
- end
115
+ @mutex.lock
116
+ docker.alerady_run? || docker.run
117
+ ensure
118
+ @mutex.unlock
119
119
  end
120
120
 
121
121
  def apply
122
122
  serve_master do |container|
123
- port = container.info["Ports"].first["PublicPort"]
123
+ port = container.info['Ports'].first['PublicPort']
124
+ https = Net::HTTP.new('localhost', port)
125
+ https.use_ssl = true
126
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
127
+ https.start do
128
+ https.delete('/puppet-admin-api/v1/environment-cache')
129
+ end
130
+
124
131
  begin
125
- tmpdir=container.info["id"][0..5]
132
+ tmpdir = container.info['id'][0..5]
126
133
  in_ssh_forwarding(port) do |host, ssh|
127
134
  Pero.log.info "#{host}:puppet cmd[#{puppet_cmd}]"
128
135
  cmd = "mkdir -p /tmp/puppet/#{tmpdir} && unshare -m -- /bin/bash -c 'export PATH=$PATH:/opt/puppetlabs/bin/ && \
@@ -131,14 +138,14 @@ module Pero
131
138
  Pero.log.debug "run cmd:#{cmd}"
132
139
  ssh_exec(ssh, host, cmd)
133
140
 
134
- if @options["one-shot"]
141
+ if @options['one-shot']
135
142
  cmd = "/bin/rm -rf /tmp/puppet/#{tmpdir}"
136
143
  ssh_exec(ssh, host, cmd)
137
144
  end
138
145
 
139
- ssh.loop {true} if ENV['PERO_DEBUG']
146
+ ssh.loop { true } if ENV['PERO_DEBUG']
140
147
  end
141
- rescue => e
148
+ rescue StandardError => e
142
149
  Pero.log.error "puppet apply error:#{e.inspect}"
143
150
  end
144
151
  end
@@ -149,15 +156,15 @@ module Pero
149
156
  def ssh_exec(ssh, host, cmd)
150
157
  ssh.open_channel do |ch|
151
158
  ch.request_pty
152
- ch.on_data do |ch,data|
159
+ ch.on_data do |_ch, data|
153
160
  Pero.log.info "#{host}:#{data.chomp}"
154
161
  end
155
162
 
156
- ch.on_extended_data do |c,type,data|
163
+ ch.on_extended_data do |_c, _type, data|
157
164
  Pero.log.error "#{host}:#{data.chomp}"
158
165
  end
159
166
 
160
- ch.exec specinfra.build_command(cmd) do |ch, success|
167
+ ch.exec specinfra.build_command(cmd) do |_ch, success|
161
168
  raise "could not execute #{cmd}" unless success
162
169
  end
163
170
  end
@@ -165,29 +172,27 @@ module Pero
165
172
  end
166
173
 
167
174
  def puppet_cmd
168
- if Gem::Version.new("5.0.0") > Gem::Version.new(@options["agent-version"])
169
- "puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --ca_port 8140 --ca_server localhost --masterport 8140 --server localhost"
170
- else
171
- "/opt/puppetlabs/bin/puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --ca_server localhost --masterport 8140 --server localhost"
172
- end
175
+ if Gem::Version.new('5.0.0') > Gem::Version.new(@options['agent-version'])
176
+ "puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --ca_port 8140 --ca_server localhost --masterport 8140 --server localhost"
177
+ else
178
+ "/opt/puppetlabs/bin/puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --ca_server localhost --masterport 8140 --server localhost"
179
+ end
173
180
  end
174
181
 
175
182
  def parse_puppet_option(options)
176
- ret = ""
177
- %w(noop verbose test).each do |n|
183
+ ret = ''
184
+ %w[noop verbose test].each do |n|
178
185
  ret << " --#{n}" if options[n]
179
186
  end
180
- ret << " --tags #{options["tags"].join(",")}" if options["tags"]
181
- ret << " --environment #{options["environment"]}" if options["environment"]
187
+ ret << " --tags #{options['tags'].join(',')}" if options['tags']
188
+ ret << " --environment #{options['environment']}" if options['environment']
182
189
  ret
183
190
  end
184
191
 
185
192
  def in_ssh_forwarding(port)
186
193
  options = specinfra.get_config(:ssh_options)
187
194
 
188
- if !Net::SSH::VALID_OPTIONS.include?(:strict_host_key_checking)
189
- options.delete(:strict_host_key_checking)
190
- end
195
+ options.delete(:strict_host_key_checking) unless Net::SSH::VALID_OPTIONS.include?(:strict_host_key_checking)
191
196
 
192
197
  Pero.log.info "start forwarding #{specinfra.get_config(:host)}:8140 => localhost:#{port}"
193
198
  Net::SSH.start(
data/lib/pero/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pero
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyama86
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  requirements: []
202
- rubygems_version: 3.4.10
202
+ rubygems_version: 3.4.19
203
203
  signing_key:
204
204
  specification_version: 4
205
205
  summary: tool for puppet apply from our desktop.