puppet-masterless 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/puppet-masterless +62 -35
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 682169b63eab3d891e86b9fc6132e9825b20d9f5
|
4
|
+
data.tar.gz: 3279bdb87fa815b546a23090248781c05c0f4dc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbd29e8b824afa0448cfb7574340be0ba30b8aa5ec95692686cdc1fe23f96f4a1f937bac8361af327298080230ffb0596270bd69112f09025ab41457a0726a55
|
7
|
+
data.tar.gz: f9cfa98d18f4127270ed7eebb8c8f033eeea74be08f95404751884a406347f47cfdb656675c080dfdb768a66eb5954ef01f4bd5eec38cd60f1ef694fb9e94331
|
data/bin/puppet-masterless
CHANGED
@@ -1,37 +1,58 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# Copyright (c) 2017-2018 Catalyst.net Ltd
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# This file is part of puppet-masterless.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# puppet-masterless is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as
|
9
|
+
# published by the Free Software Foundation, either version 3 of the
|
10
|
+
# License, or (at your option) any later version.
|
8
11
|
#
|
9
|
-
#
|
10
|
-
#
|
12
|
+
# puppet-masterless is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
# General Public License for more details.
|
11
16
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# confdir <pathname> - main project directory
|
15
|
-
# manifest <filename> - manifest to apply
|
16
|
-
# hiera_config <filename> - passed to --hiera_config
|
17
|
-
# modulepath <pathname> - passed to --modulepath
|
18
|
-
# puppet <executable> - location of puppet executable
|
19
|
-
# to <hostname> - hostname of remote machine
|
20
|
-
# as <username> - name of user running puppet-apply
|
21
|
-
# file <filename> - include a file or directory
|
22
|
-
# output file <filename> - output filename
|
23
|
-
#
|
24
|
-
# At least "confdir" must be specified.
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with puppet-masterless. If not, see http://www.gnu.org/licenses/
|
25
19
|
#
|
26
20
|
|
27
21
|
require 'fileutils'
|
28
|
-
require 'shellwords'
|
29
22
|
require 'securerandom'
|
23
|
+
require 'shellwords'
|
24
|
+
|
25
|
+
#|
|
26
|
+
#| Usage: puppet-masterless <command> [<argument> ...] [-- puppet arguments ...]
|
27
|
+
#|
|
28
|
+
#| Applies a local puppet project to a remote host.
|
29
|
+
#|
|
30
|
+
#| Available commands:
|
31
|
+
#|
|
32
|
+
#| apply - apply a project to a remote host
|
33
|
+
#| package - package a project as a shell script
|
34
|
+
#|
|
35
|
+
#| Available arguments:
|
36
|
+
#|
|
37
|
+
#| confdir <pathname> - main project directory
|
38
|
+
#| manifest <filename> - manifest to apply
|
39
|
+
#| hiera_config <filename> - passed to --hiera_config
|
40
|
+
#| modulepath <pathname> - passed to --modulepath
|
41
|
+
#| to <hostname> - hostname of remote machine
|
42
|
+
#| puppet <executable> - location of puppet executable on remote host
|
43
|
+
#| sudo <command> - location of sudo executable on remote host
|
44
|
+
#| as <username> - name of user running puppet-apply
|
45
|
+
#| file <filename> - add file or directory to package
|
46
|
+
#| output file <filename> - output filename for package
|
47
|
+
#|
|
48
|
+
#| At least "confdir" must be specified.
|
49
|
+
#|
|
30
50
|
|
31
51
|
module PuppetMasterless
|
32
52
|
ARCHIVE_NAME = 'puppet-package'
|
33
53
|
ARCHIVE_OPTIONS = '--ignore-failed-read --exclude-vcs'
|
34
54
|
DEFAULT_PUPPET = 'puppet'
|
55
|
+
DEFAULT_SUDO = 'sudo'
|
35
56
|
REMOTE_USER = 'root'
|
36
57
|
REMOTE_WORKDIR = '/tmp'
|
37
58
|
|
@@ -41,6 +62,7 @@ module PuppetMasterless
|
|
41
62
|
@args = []
|
42
63
|
@path = ARCHIVE_NAME
|
43
64
|
@puppet = DEFAULT_PUPPET
|
65
|
+
@sudo = DEFAULT_SUDO
|
44
66
|
@user = REMOTE_USER
|
45
67
|
@workdir = REMOTE_WORKDIR
|
46
68
|
@output = "#{ARCHIVE_NAME}-#{SecureRandom.hex(4)}"
|
@@ -60,6 +82,7 @@ module PuppetMasterless
|
|
60
82
|
when 'modulepath' then @modulepath = args.shift
|
61
83
|
when 'hiera_config' then @hiera_config = args.shift
|
62
84
|
when 'puppet' then @puppet = args.shift
|
85
|
+
when 'sudo' then @sudo = args.shift
|
63
86
|
when 'to' then @hostname = args.shift
|
64
87
|
when 'as' then @user = args.shift
|
65
88
|
when 'file' then @files << args.shift
|
@@ -75,17 +98,24 @@ module PuppetMasterless
|
|
75
98
|
fail 'No puppet specified' unless @puppet
|
76
99
|
fail 'No output file specified' unless @output
|
77
100
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
101
|
+
modules = File.join(@confdir, 'modules')
|
102
|
+
manifests = File.join(@confdir, 'manifests')
|
103
|
+
hieradata = File.join(@confdir, 'hieradata')
|
104
|
+
hiera_yaml = File.join(@confdir, 'hiera.yaml')
|
105
|
+
puppet_conf = File.join(@confdir, 'puppet.conf')
|
106
|
+
|
107
|
+
@manifest ||= manifests
|
108
|
+
@modulepath ||= modules
|
109
|
+
@hiera_config ||= hiera_yaml
|
82
110
|
|
83
111
|
fail 'No such confdir: ' << @confdir unless File.directory?(@confdir)
|
84
112
|
fail 'No such manifest: ' << @manifest unless File.exist?(@manifest)
|
85
113
|
|
114
|
+
@files << hieradata if File.directory?(hieradata)
|
115
|
+
@files << puppet_conf if File.file?(puppet_conf)
|
116
|
+
|
86
117
|
@modulepath = nil unless File.directory?(@modulepath)
|
87
118
|
@hiera_config = nil unless File.file?(@hiera_config)
|
88
|
-
@hieradata = nil unless File.directory?(@hieradata)
|
89
119
|
end
|
90
120
|
|
91
121
|
def package
|
@@ -99,7 +129,7 @@ module PuppetMasterless
|
|
99
129
|
private
|
100
130
|
|
101
131
|
def banner
|
102
|
-
File.read(__FILE__).lines
|
132
|
+
File.read(__FILE__).lines.grep(/^#\|/).map { |s| s.gsub(/^#\| ?/, '') }
|
103
133
|
end
|
104
134
|
|
105
135
|
def collect_output(args)
|
@@ -113,23 +143,19 @@ module PuppetMasterless
|
|
113
143
|
command << ' ' << @manifest.shellescape
|
114
144
|
command << ' ' << @modulepath.shellescape if @modulepath
|
115
145
|
command << ' ' << @hiera_config.shellescape if @hiera_config
|
116
|
-
command << ' ' << @hieradata.shellescape if @hieradata
|
117
146
|
command << ' | gzip -f'
|
118
147
|
end
|
119
148
|
|
120
149
|
def local_apply_command
|
121
|
-
command = "
|
150
|
+
command = "#{@puppet} apply #{@manifest.shellescape} --verbose --show_diff --color true"
|
151
|
+
command << ' --confdir ' << @confdir.shellescape
|
122
152
|
command << ' --modulepath ' << @modulepath.shellescape if @modulepath
|
123
153
|
command << ' --hiera_config ' << @hiera_config.shellescape if @hiera_config
|
124
154
|
command << ' ' << @args.shelljoin
|
125
155
|
end
|
126
156
|
|
127
157
|
def remote_apply_command
|
128
|
-
"sudo -u #{@user.shellescape} #{@workdir.shellescape}/#{@output.shellescape}"
|
129
|
-
end
|
130
|
-
|
131
|
-
def remote_cleanup_command
|
132
|
-
"sudo -u #{@user.shellescape} rm -f #{@workdir.shellescape}/#{@output.shellescape} -r #{@workdir.shellescape}/#{@path.shellescape}"
|
158
|
+
"#{@sudo} -u #{@user.shellescape} #{@workdir.shellescape}/#{@output.shellescape}"
|
133
159
|
end
|
134
160
|
|
135
161
|
def apply_local
|
@@ -148,7 +174,7 @@ module PuppetMasterless
|
|
148
174
|
fail 'Apply command failed' unless system("ssh -q -t #{@hostname.shellescape} #{remote_apply_command.shellescape}")
|
149
175
|
ensure
|
150
176
|
FileUtils.rm_f(@output)
|
151
|
-
system("ssh -q -t #{@hostname.shellescape} #{
|
177
|
+
system("ssh -q -t #{@hostname.shellescape} rm -f #{@workdir.shellescape}/#{@output.shellescape}")
|
152
178
|
end
|
153
179
|
|
154
180
|
def create_distribution
|
@@ -156,10 +182,11 @@ module PuppetMasterless
|
|
156
182
|
o.puts('#!/bin/sh -e')
|
157
183
|
o.puts('umask 077')
|
158
184
|
o.puts('cd "$(dirname "$0")"')
|
159
|
-
o.puts('
|
185
|
+
o.puts('trap "rm -rf ' << @workdir.shellescape << '/' << @path.shellescape << '" EXIT')
|
186
|
+
o.puts('sed -n 10,\\$p "$0" | gunzip -f | tar -xf-')
|
160
187
|
o.puts('cd ' << @path.shellescape)
|
161
188
|
o.puts(local_apply_command)
|
162
|
-
o.puts('exit
|
189
|
+
o.puts('exit 0')
|
163
190
|
o.puts('# EOF')
|
164
191
|
o.chmod(0755)
|
165
192
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-masterless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Hanson
|
@@ -10,8 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Packages and
|
14
|
-
host via SSH.
|
13
|
+
description: Packages and applies a Puppet project to a remote host.
|
15
14
|
email: evanh@catalyst.net.nz
|
16
15
|
executables:
|
17
16
|
- puppet-masterless
|
@@ -19,7 +18,7 @@ extensions: []
|
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
20
|
- bin/puppet-masterless
|
22
|
-
homepage: https://gitlab.
|
21
|
+
homepage: https://gitlab.com/catalyst-it/puppet-masterless
|
23
22
|
licenses:
|
24
23
|
- GPLv3
|
25
24
|
metadata: {}
|
@@ -42,5 +41,5 @@ rubyforge_project:
|
|
42
41
|
rubygems_version: 2.6.12
|
43
42
|
signing_key:
|
44
43
|
specification_version: 4
|
45
|
-
summary: Apply a local
|
44
|
+
summary: Apply a local Puppet project to a remote host
|
46
45
|
test_files: []
|