simp-cli 1.0.12
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 +15 -0
- data/LICENSE +27 -0
- data/README.md +48 -0
- data/Rakefile +142 -0
- data/bin/simp +5 -0
- data/lib/simp/cli.rb +88 -0
- data/lib/simp/cli/commands/bootstrap.rb +275 -0
- data/lib/simp/cli/commands/check.rb +163 -0
- data/lib/simp/cli/commands/cleancerts.rb +114 -0
- data/lib/simp/cli/commands/config.rb +235 -0
- data/lib/simp/cli/commands/doc.rb +14 -0
- data/lib/simp/cli/commands/passgen.rb +128 -0
- data/lib/simp/cli/commands/puppeteval.rb +82 -0
- data/lib/simp/cli/commands/runpuppet.rb +95 -0
- data/lib/simp/cli/config/item.rb +456 -0
- data/lib/simp/cli/config/item/add_ldap_to_hiera.rb +43 -0
- data/lib/simp/cli/config/item/answers_yaml_file_writer.rb +58 -0
- data/lib/simp/cli/config/item/certificates.rb +39 -0
- data/lib/simp/cli/config/item/client_nets.rb +65 -0
- data/lib/simp/cli/config/item/common_runlevel_default.rb +32 -0
- data/lib/simp/cli/config/item/dns_search.rb +48 -0
- data/lib/simp/cli/config/item/dns_servers.rb +57 -0
- data/lib/simp/cli/config/item/failover_log_servers.rb +27 -0
- data/lib/simp/cli/config/item/gateway.rb +32 -0
- data/lib/simp/cli/config/item/grub_password.rb +51 -0
- data/lib/simp/cli/config/item/hostname.rb +24 -0
- data/lib/simp/cli/config/item/hostname_conf.rb +48 -0
- data/lib/simp/cli/config/item/ipaddress.rb +46 -0
- data/lib/simp/cli/config/item/is_master_yum_server.rb +23 -0
- data/lib/simp/cli/config/item/ldap_base_dn.rb +38 -0
- data/lib/simp/cli/config/item/ldap_bind_dn.rb +34 -0
- data/lib/simp/cli/config/item/ldap_bind_hash.rb +28 -0
- data/lib/simp/cli/config/item/ldap_bind_pw.rb +24 -0
- data/lib/simp/cli/config/item/ldap_master.rb +33 -0
- data/lib/simp/cli/config/item/ldap_root_dn.rb +42 -0
- data/lib/simp/cli/config/item/ldap_root_hash.rb +35 -0
- data/lib/simp/cli/config/item/ldap_sync_dn.rb +24 -0
- data/lib/simp/cli/config/item/ldap_sync_hash.rb +28 -0
- data/lib/simp/cli/config/item/ldap_sync_pw.rb +26 -0
- data/lib/simp/cli/config/item/ldap_uri.rb +43 -0
- data/lib/simp/cli/config/item/log_servers.rb +27 -0
- data/lib/simp/cli/config/item/netmask.rb +39 -0
- data/lib/simp/cli/config/item/network_conf.rb +63 -0
- data/lib/simp/cli/config/item/network_dhcp.rb +27 -0
- data/lib/simp/cli/config/item/network_interface.rb +41 -0
- data/lib/simp/cli/config/item/network_setup_nic.rb +28 -0
- data/lib/simp/cli/config/item/ntp_servers.rb +69 -0
- data/lib/simp/cli/config/item/puppet_autosign.rb +66 -0
- data/lib/simp/cli/config/item/puppet_ca.rb +31 -0
- data/lib/simp/cli/config/item/puppet_ca_port.rb +28 -0
- data/lib/simp/cli/config/item/puppet_conf.rb +98 -0
- data/lib/simp/cli/config/item/puppet_fileserver.rb +104 -0
- data/lib/simp/cli/config/item/puppet_hosts_entry.rb +44 -0
- data/lib/simp/cli/config/item/puppet_server.rb +30 -0
- data/lib/simp/cli/config/item/puppet_server_ip.rb +25 -0
- data/lib/simp/cli/config/item/puppetdb_port.rb +25 -0
- data/lib/simp/cli/config/item/puppetdb_server.rb +26 -0
- data/lib/simp/cli/config/item/remove_ldap_from_hiera.rb +47 -0
- data/lib/simp/cli/config/item/rename_fqdn_yaml.rb +40 -0
- data/lib/simp/cli/config/item/rsync_base.rb +37 -0
- data/lib/simp/cli/config/item/rsync_server.rb +44 -0
- data/lib/simp/cli/config/item/rsync_timeout.rb +26 -0
- data/lib/simp/cli/config/item/set_grub_password.rb +19 -0
- data/lib/simp/cli/config/item/simp_yum_servers.rb +30 -0
- data/lib/simp/cli/config/item/use_auditd.rb +19 -0
- data/lib/simp/cli/config/item/use_fips.rb +46 -0
- data/lib/simp/cli/config/item/use_iptables.rb +22 -0
- data/lib/simp/cli/config/item/use_ldap.rb +19 -0
- data/lib/simp/cli/config/item/use_selinux.rb +32 -0
- data/lib/simp/cli/config/item/yum_repositories.rb +75 -0
- data/lib/simp/cli/config/item_list_factory.rb +236 -0
- data/lib/simp/cli/config/questionnaire.rb +86 -0
- data/lib/simp/cli/config/utils.rb +128 -0
- data/lib/simp/cli/lib/utils.rb +114 -0
- data/lib/simp/simp.rb +77 -0
- data/spec/lib/simp/cli/commands/config_spec.rb +42 -0
- data/spec/lib/simp/cli/config/item/add_ldap_to_hiera_spec.rb +58 -0
- data/spec/lib/simp/cli/config/item/answers_yaml_file_writer_spec.rb +86 -0
- data/spec/lib/simp/cli/config/item/certificates_spec.rb +50 -0
- data/spec/lib/simp/cli/config/item/client_nets_spec.rb +66 -0
- data/spec/lib/simp/cli/config/item/common_runlevel_default_spec.rb +27 -0
- data/spec/lib/simp/cli/config/item/dns_search_spec.rb +74 -0
- data/spec/lib/simp/cli/config/item/dns_servers_spec.rb +76 -0
- data/spec/lib/simp/cli/config/item/failover_log_servers_spec.rb +49 -0
- data/spec/lib/simp/cli/config/item/files/FakeCA/cacertkey +1 -0
- data/spec/lib/simp/cli/config/item/files/FakeCA/gencerts_nopass.sh +10 -0
- data/spec/lib/simp/cli/config/item/files/autosign.conf.new +11 -0
- data/spec/lib/simp/cli/config/item/files/autosign.conf.used +15 -0
- data/spec/lib/simp/cli/config/item/files/fileserver.conf +41 -0
- data/spec/lib/simp/cli/config/item/files/hosts +2 -0
- data/spec/lib/simp/cli/config/item/files/hosts.old_puppet_entry +3 -0
- data/spec/lib/simp/cli/config/item/files/puppet.conf +25 -0
- data/spec/lib/simp/cli/config/item/files/puppet.your.domain.yaml +21 -0
- data/spec/lib/simp/cli/config/item/files/resolv.conf__multiple +10 -0
- data/spec/lib/simp/cli/config/item/files/resolv.conf__single +4 -0
- data/spec/lib/simp/cli/config/item/files/rsyncd.conf +225 -0
- data/spec/lib/simp/cli/config/item/gateway_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/grub_password_spec.rb +24 -0
- data/spec/lib/simp/cli/config/item/hostname_conf_spec.rb +27 -0
- data/spec/lib/simp/cli/config/item/hostname_spec.rb +22 -0
- data/spec/lib/simp/cli/config/item/ipaddress_spec.rb +40 -0
- data/spec/lib/simp/cli/config/item/is_master_yum_server_spec.rb +29 -0
- data/spec/lib/simp/cli/config/item/ldap_base_dn_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/ldap_bind_dn_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/ldap_bind_hash_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/ldap_bind_pw_spec.rb +21 -0
- data/spec/lib/simp/cli/config/item/ldap_master_spec.rb +37 -0
- data/spec/lib/simp/cli/config/item/ldap_root_dn_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/ldap_root_hash_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/ldap_sync_dn_spec.rb +22 -0
- data/spec/lib/simp/cli/config/item/ldap_sync_hash_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/ldap_sync_pw_spec.rb +21 -0
- data/spec/lib/simp/cli/config/item/ldap_uri_spec.rb +32 -0
- data/spec/lib/simp/cli/config/item/log_servers_spec.rb +49 -0
- data/spec/lib/simp/cli/config/item/netmask_spec.rb +28 -0
- data/spec/lib/simp/cli/config/item/network_conf_spec.rb +63 -0
- data/spec/lib/simp/cli/config/item/network_dhcp_spec.rb +11 -0
- data/spec/lib/simp/cli/config/item/network_interface_spec.rb +26 -0
- data/spec/lib/simp/cli/config/item/network_setup_nic_spec.rb +29 -0
- data/spec/lib/simp/cli/config/item/ntp_servers_spec.rb +43 -0
- data/spec/lib/simp/cli/config/item/puppet_autosign_spec.rb +55 -0
- data/spec/lib/simp/cli/config/item/puppet_ca_port_spec.rb +23 -0
- data/spec/lib/simp/cli/config/item/puppet_ca_spec.rb +22 -0
- data/spec/lib/simp/cli/config/item/puppet_conf_spec.rb +110 -0
- data/spec/lib/simp/cli/config/item/puppet_fileserver_spec.rb +53 -0
- data/spec/lib/simp/cli/config/item/puppet_hosts_entry_spec.rb +85 -0
- data/spec/lib/simp/cli/config/item/puppet_server_ip_spec.rb +24 -0
- data/spec/lib/simp/cli/config/item/puppet_server_spec.rb +22 -0
- data/spec/lib/simp/cli/config/item/puppetdb_port_spec.rb +25 -0
- data/spec/lib/simp/cli/config/item/puppetdb_server_spec.rb +25 -0
- data/spec/lib/simp/cli/config/item/remove_ldap_from_hiera_spec.rb +58 -0
- data/spec/lib/simp/cli/config/item/rename_fqdn_yaml_spec.rb +63 -0
- data/spec/lib/simp/cli/config/item/rsync_base_spec.rb +28 -0
- data/spec/lib/simp/cli/config/item/rsync_server_spec.rb +41 -0
- data/spec/lib/simp/cli/config/item/rsync_timeout_spec.rb +21 -0
- data/spec/lib/simp/cli/config/item/set_grub_password_spec.rb +29 -0
- data/spec/lib/simp/cli/config/item/simp_yum_servers_spec.rb +41 -0
- data/spec/lib/simp/cli/config/item/spec_helper.rb +22 -0
- data/spec/lib/simp/cli/config/item/use_auditd_spec.rb +29 -0
- data/spec/lib/simp/cli/config/item/use_fips_spec.rb +29 -0
- data/spec/lib/simp/cli/config/item/use_iptables_spec.rb +29 -0
- data/spec/lib/simp/cli/config/item/use_ldap_spec.rb +29 -0
- data/spec/lib/simp/cli/config/item/use_selinux_spec.rb +24 -0
- data/spec/lib/simp/cli/config/item/yum_repositories_spec.rb +94 -0
- data/spec/lib/simp/cli/config/item_spec.rb +106 -0
- data/spec/lib/simp/cli/config/spec_helper.rb +1 -0
- data/spec/lib/simp/cli/config/utils_spec.rb +131 -0
- data/spec/lib/simp/cli/spec_helper.rb +1 -0
- data/spec/spec_helper.rb +91 -0
- metadata +391 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'highline/import'
|
|
2
|
+
require 'puppet'
|
|
3
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
4
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
5
|
+
|
|
6
|
+
module Simp; end
|
|
7
|
+
class Simp::Cli; end
|
|
8
|
+
module Simp::Cli::Config
|
|
9
|
+
class Item::PuppetCAPort < Item
|
|
10
|
+
def initialize
|
|
11
|
+
super
|
|
12
|
+
@key = 'puppet::ca_port'
|
|
13
|
+
@description = 'The port which the Puppet CA will listen on (8141 by default).'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def os_value
|
|
17
|
+
Puppet.settings.setting( 'ca_port' ).value
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def validate( x )
|
|
21
|
+
(x.to_s =~ /^\d+$/ ? true : false ) && x.to_i > 0 && x.to_i <= 65535
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def recommended_value
|
|
25
|
+
8141
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require 'highline/import'
|
|
2
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
3
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
4
|
+
|
|
5
|
+
module Simp; end
|
|
6
|
+
class Simp::Cli; end
|
|
7
|
+
module Simp::Cli::Config
|
|
8
|
+
class Item::PuppetConf < ActionItem
|
|
9
|
+
attr_accessor :file
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
super
|
|
13
|
+
@key = 'puppet::conf'
|
|
14
|
+
@description = 'silent item; configures /etc/puppet/puppet.conf'
|
|
15
|
+
# FIXME: this path will change with Puppet Enterprise; should this autodetect?
|
|
16
|
+
@file = '/etc/puppet/puppet.conf'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# NOTE: This is (mostly) lifted straight from the old simp config
|
|
20
|
+
# TODO: refactor sed statements to pure ruby,
|
|
21
|
+
# consider using IO handles instead of File.open (easier to test in memory)?
|
|
22
|
+
# or use Puppet::Settings ( https://github.com/puppetlabs/puppet/blob/master/lib/puppet/settings.rb )?
|
|
23
|
+
def apply
|
|
24
|
+
say_green "Updating #{@file}..." if !@silent
|
|
25
|
+
if @skip_apply
|
|
26
|
+
say_yellow "WARNING: directed to skip Puppet configuration of #{file}" if !@silent
|
|
27
|
+
return
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
backup_file = "#{@file}.pre_simpconfig"
|
|
31
|
+
FileUtils.cp("#{@file}", backup_file)
|
|
32
|
+
`sed -i '/^\s*server.*/d' #{@file}`
|
|
33
|
+
`sed -i '/.*trusted_node_data.*/d' #{@file}`
|
|
34
|
+
`sed -i '/.*digest_algorithm.*/d' #{@file}`
|
|
35
|
+
`sed -i '/.*stringify_facts.*/d' #{@file}`
|
|
36
|
+
`sed -i '/.*environment_path.*/d' #{@file}`
|
|
37
|
+
`sed -i '/^.main./ a \\ trusted_node_data = true\' #{@file}`
|
|
38
|
+
`sed -i '/^.main./ a \\ digest_algorithm = sha256\' #{@file}`
|
|
39
|
+
`sed -i '/^.main./ a \\ stringify_facts = false\' #{@file}`
|
|
40
|
+
`sed -i '/^.main./ a \\ environmentpath = /etc/puppet/environments\' #{@file}`
|
|
41
|
+
`sed -i '/trusted_node_data/ a \\ server = #{@config_items.fetch( 'puppet::server' ).value}\' #{@file}`
|
|
42
|
+
keylength = @config_items.fetch( 'use_fips', nil )? '2048' : '4096'
|
|
43
|
+
`sed -i '/^.main./ a \\ keylength = #{keylength}\' #{@file}`
|
|
44
|
+
|
|
45
|
+
# do not die if config items aren't found
|
|
46
|
+
puppet_server = 'puppet.change.me'
|
|
47
|
+
puppet_ca = 'puppetca.change.me'
|
|
48
|
+
puppet_ca_port = '8141'
|
|
49
|
+
if item = @config_items.fetch( 'puppet::server', nil )
|
|
50
|
+
puppet_server = item.value
|
|
51
|
+
end
|
|
52
|
+
if item = @config_items.fetch( 'puppet::ca', nil )
|
|
53
|
+
puppet_ca = item.value
|
|
54
|
+
end
|
|
55
|
+
if item = @config_items.fetch( 'puppet::ca_port', nil )
|
|
56
|
+
puppet_ca_port = item.value
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
puppet_conf = File.readlines(@file)
|
|
60
|
+
File.open("#{@file}", 'w') do |out_file|
|
|
61
|
+
line_check = {
|
|
62
|
+
'server' => false,
|
|
63
|
+
'ca_server' => false,
|
|
64
|
+
'ca_port' => false
|
|
65
|
+
}
|
|
66
|
+
puppet_conf.each do |line|
|
|
67
|
+
if line !~ /^\s*(#{line_check.keys.join('|')})(\s*=\s*)/
|
|
68
|
+
out_file.puts line
|
|
69
|
+
else
|
|
70
|
+
$1.chomp
|
|
71
|
+
line_check[$1] = true
|
|
72
|
+
case $1
|
|
73
|
+
when 'server' then
|
|
74
|
+
out_file.puts " #{$1}#{$2}#{puppet_server}"
|
|
75
|
+
when 'ca_server' then
|
|
76
|
+
out_file.puts " #{$1}#{$2}#{puppet_ca}"
|
|
77
|
+
when 'ca_port' then
|
|
78
|
+
out_file.puts " #{$1}#{$2}#{puppet_ca_port}"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
line_check.keys.each do |key|
|
|
83
|
+
if not line_check[key] then
|
|
84
|
+
case key
|
|
85
|
+
when 'server' then
|
|
86
|
+
out_file.puts " server = #{puppet_server}"
|
|
87
|
+
when 'ca_server' then
|
|
88
|
+
out_file.puts " ca_server = #{puppet_ca}"
|
|
89
|
+
when 'ca_port' then
|
|
90
|
+
out_file.puts " ca_port = #{puppet_ca_port}"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require 'highline/import'
|
|
2
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
3
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
4
|
+
|
|
5
|
+
module Simp; end
|
|
6
|
+
class Simp::Cli; end
|
|
7
|
+
module Simp::Cli::Config
|
|
8
|
+
class Item::PuppetFileServer < ActionItem
|
|
9
|
+
|
|
10
|
+
attr_accessor :file
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
super
|
|
14
|
+
@key = 'puppet::fileserver'
|
|
15
|
+
@description = 'silent item; configures /etc/puppet/fileserver.conf'
|
|
16
|
+
@file = '/etc/puppet/fileserver.conf'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def apply
|
|
20
|
+
say_green " updating Puppet configurations in #{@file}..." if !@silent
|
|
21
|
+
|
|
22
|
+
conf = @file
|
|
23
|
+
|
|
24
|
+
require 'fileutils'
|
|
25
|
+
FileUtils.cp(conf, "#{conf}.pre_simpconfig")
|
|
26
|
+
|
|
27
|
+
hostname = @config_items.fetch( 'hostname' ) #FIXME: should this be hostname or puppet_server?
|
|
28
|
+
domain = hostname.value.split('.')[1..-1].join('.')
|
|
29
|
+
|
|
30
|
+
if !domain or domain.empty?
|
|
31
|
+
raise "Could not determine domain from hostname '#{hostname}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
default_entries = ['facts','plugins','keydist','cacerts','mcollective']
|
|
35
|
+
|
|
36
|
+
fileserver_default = <<-EOM
|
|
37
|
+
[facts]
|
|
38
|
+
path /etc/puppet/facts
|
|
39
|
+
allow *.#{domain}
|
|
40
|
+
|
|
41
|
+
[plugins]
|
|
42
|
+
allow *.#{domain}
|
|
43
|
+
|
|
44
|
+
[keydist]
|
|
45
|
+
path /etc/puppet/keydist/%H
|
|
46
|
+
allow *.#{domain}
|
|
47
|
+
|
|
48
|
+
[cacerts]
|
|
49
|
+
path /etc/puppet/keydist/cacerts
|
|
50
|
+
allow *.#{domain}
|
|
51
|
+
|
|
52
|
+
[mcollective]
|
|
53
|
+
path /etc/puppet/keydist/mcollective
|
|
54
|
+
allow *.#{domain}
|
|
55
|
+
EOM
|
|
56
|
+
|
|
57
|
+
# Complete crib from StackOverflow
|
|
58
|
+
fileserver_default.gsub!(/^#{fileserver_default[/\A\s*/]}/,'')
|
|
59
|
+
|
|
60
|
+
fileserver_new = []
|
|
61
|
+
|
|
62
|
+
fileserver_old = File.read(conf).split("\n")
|
|
63
|
+
|
|
64
|
+
# Preserve any beginning comments
|
|
65
|
+
while fileserver_old[0] =~ /^\s*(#.*|\s*)$/ do
|
|
66
|
+
fileserver_new << fileserver_old.shift
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Add in our defaults
|
|
70
|
+
fileserver_new << fileserver_default
|
|
71
|
+
|
|
72
|
+
# Read the rest of the file, ignoring any section that we're going to
|
|
73
|
+
# replace.
|
|
74
|
+
key = nil
|
|
75
|
+
comments = []
|
|
76
|
+
fileserver_old.each do |line|
|
|
77
|
+
if line =~ /\[(.*)\]/ then
|
|
78
|
+
key = $1.strip
|
|
79
|
+
comments = []
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
next if default_entries.include?(key)
|
|
83
|
+
|
|
84
|
+
fileserver_new << line
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# If the last entry was a default entry key, preserve the trailing file
|
|
88
|
+
# comments (if any)
|
|
89
|
+
if default_entries.include?(key) then
|
|
90
|
+
fileserver_new << "\n"
|
|
91
|
+
fileserver_new += comments
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Smash duplicates
|
|
95
|
+
fileserver_new.each_with_index do |x,i|
|
|
96
|
+
fileserver_new.delete(i) unless fileserver_new[i] != fileserver_new[i + 1]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
File.open(conf,'w'){|x| x.puts(fileserver_new.join("\n"))}
|
|
100
|
+
|
|
101
|
+
true
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "resolv"
|
|
2
|
+
require 'highline/import'
|
|
3
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
4
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
5
|
+
|
|
6
|
+
module Simp; end
|
|
7
|
+
class Simp::Cli; end
|
|
8
|
+
module Simp::Cli::Config
|
|
9
|
+
class Item::PuppetHostsEntry < ActionItem
|
|
10
|
+
attr_accessor :file
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
super
|
|
14
|
+
@key = 'puppet::hosts_entry'
|
|
15
|
+
@description = %Q{Ensures an entry for the puppet server in /etc/hosts (apply-only; noop).}
|
|
16
|
+
@file = '/etc/hosts'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def apply
|
|
20
|
+
puppet_server = @config_items.fetch( 'puppet::server' ).value
|
|
21
|
+
puppet_server_ip = @config_items.fetch( 'puppet::server::ip' ).value
|
|
22
|
+
status = false
|
|
23
|
+
|
|
24
|
+
say_green "Updating #{@file}..." if !@silent
|
|
25
|
+
|
|
26
|
+
values = Array.new
|
|
27
|
+
File.readlines(@file).each do |line|
|
|
28
|
+
next if line =~ /\s*#/
|
|
29
|
+
next if line =~ /#{puppet_server}/ and @value.eql?(puppet_server)
|
|
30
|
+
next if line =~ /localdomain/
|
|
31
|
+
next if line =~ /localdomain6/
|
|
32
|
+
next if line =~ /\spuppet(\s|$)/ # remove alias 'puppet'
|
|
33
|
+
values.push(line)
|
|
34
|
+
end
|
|
35
|
+
File.open(@file,'w') {|fh|
|
|
36
|
+
fh.puts('127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4')
|
|
37
|
+
fh.puts('::1 localhost localhost.localdomain localhost6 localhost6.localdomain6')
|
|
38
|
+
fh.puts("#{puppet_server_ip} #{puppet_server} #{puppet_server.split('.').first}")
|
|
39
|
+
fh.puts(values)
|
|
40
|
+
}
|
|
41
|
+
true
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'highline/import'
|
|
2
|
+
require 'puppet'
|
|
3
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
4
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
5
|
+
|
|
6
|
+
module Simp; end
|
|
7
|
+
class Simp::Cli; end
|
|
8
|
+
module Simp::Cli::Config
|
|
9
|
+
class Item::PuppetServer < Item
|
|
10
|
+
def initialize
|
|
11
|
+
super
|
|
12
|
+
@key = 'puppet::server'
|
|
13
|
+
@description = %q{The Hostname or FQDN of the puppet server.}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def os_value
|
|
17
|
+
Puppet.settings.setting( 'server' ).value
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def validate( x )
|
|
21
|
+
Simp::Cli::Config::Utils.validate_hostname( x ) ||
|
|
22
|
+
Simp::Cli::Config::Utils.validate_fqdn( x )
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def recommended_value
|
|
26
|
+
item = @config_items.fetch( 'hostname', nil )
|
|
27
|
+
item.value if item
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
2
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
3
|
+
|
|
4
|
+
module Simp; end
|
|
5
|
+
class Simp::Cli; end
|
|
6
|
+
module Simp::Cli::Config
|
|
7
|
+
class Item::PuppetServerIP < Item
|
|
8
|
+
def initialize
|
|
9
|
+
super
|
|
10
|
+
@key = 'puppet::server::ip'
|
|
11
|
+
@description = %Q{The Puppet server's IP address.\nThis is used to configure /etc/hosts properly.}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Always recommend the configured IP
|
|
16
|
+
def recommended_value
|
|
17
|
+
@config_items.fetch( 'ipaddress' ).value
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def validate( x )
|
|
22
|
+
Simp::Cli::Config::Utils.validate_ip x
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
2
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
3
|
+
|
|
4
|
+
module Simp; end
|
|
5
|
+
class Simp::Cli; end
|
|
6
|
+
|
|
7
|
+
module Simp::Cli::Config
|
|
8
|
+
class Item::PuppetDBPort < Item
|
|
9
|
+
def initialize
|
|
10
|
+
super
|
|
11
|
+
@key = 'puppetdb::master::config::puppetdb_port'
|
|
12
|
+
@description = %Q{The PuppetDB server port number}
|
|
13
|
+
@value = recommended_value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def recommended_value
|
|
17
|
+
'8139'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def validate string
|
|
21
|
+
( string =~ /^\d+$/ ? true : false ) &&
|
|
22
|
+
( string.to_i > 1 && string.to_i < 65536 )
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
2
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
3
|
+
|
|
4
|
+
module Simp; end
|
|
5
|
+
class Simp::Cli; end
|
|
6
|
+
|
|
7
|
+
module Simp::Cli::Config
|
|
8
|
+
class Item::PuppetDBServer < Item
|
|
9
|
+
def initialize
|
|
10
|
+
super
|
|
11
|
+
@key = 'puppetdb::master::config::puppetdb_server'
|
|
12
|
+
@description = %Q{The dns name or ip of the puppetdb server}
|
|
13
|
+
@value = recommended_value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def recommended_value
|
|
17
|
+
"%{hiera('puppet::server')}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def validate string
|
|
21
|
+
Simp::Cli::Config::Utils.validate_fqdn( string ) ||
|
|
22
|
+
Simp::Cli::Config::Utils.validate_ip( string ) ||
|
|
23
|
+
Simp::Cli::Config::Utils.validate_hiera_lookup( string )
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "resolv"
|
|
2
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
3
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
4
|
+
|
|
5
|
+
module Simp; end
|
|
6
|
+
class Simp::Cli; end
|
|
7
|
+
module Simp::Cli::Config
|
|
8
|
+
class Item::RemoveLdapFromHiera < ActionItem
|
|
9
|
+
attr_accessor :dir
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
super
|
|
13
|
+
@key = 'puppet::remove_ldap_from_hiera'
|
|
14
|
+
@description = %Q{Removes any ldap classes from hieradata/hosts/puppet.your.domain.yaml (apply-only; noop).}
|
|
15
|
+
@dir = "/etc/puppet/environments/simp/hieradata/hosts"
|
|
16
|
+
@file = nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def apply
|
|
20
|
+
success = true
|
|
21
|
+
fqdn = @config_items.fetch( 'hostname' ).value
|
|
22
|
+
file = File.join( @dir, "#{fqdn}.yaml")
|
|
23
|
+
|
|
24
|
+
say_green 'Removing ldap classes from the <domain>.yaml file' if !@silent
|
|
25
|
+
|
|
26
|
+
if File.exists?(file)
|
|
27
|
+
lines = File.open(file,'r').readlines
|
|
28
|
+
|
|
29
|
+
File.open(file, 'w') do |f|
|
|
30
|
+
lines.each do |line|
|
|
31
|
+
line.chomp!
|
|
32
|
+
f.puts line if !strip_line?(line)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
else
|
|
36
|
+
success = false
|
|
37
|
+
say_yellow "WARNING: file not found: #{file}"
|
|
38
|
+
end
|
|
39
|
+
success
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def strip_line?( line )
|
|
44
|
+
(line =~ /^\s*-\s+(([a-z_:'"]*::)*(open)*ldap|(open)*ldap[a-z_:'"]*)/m) ? true : false
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require "resolv"
|
|
2
|
+
require 'highline/import'
|
|
3
|
+
require File.expand_path( '../item', File.dirname(__FILE__) )
|
|
4
|
+
require File.expand_path( '../utils', File.dirname(__FILE__) )
|
|
5
|
+
|
|
6
|
+
module Simp; end
|
|
7
|
+
class Simp::Cli; end
|
|
8
|
+
module Simp::Cli::Config
|
|
9
|
+
class Item::RenameFqdnYaml < ActionItem
|
|
10
|
+
attr_accessor :file
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
super
|
|
14
|
+
@key = 'puppet::rename_fqdn_yaml'
|
|
15
|
+
@description = %Q{Renames hieradata/hosts/puppet.your.domain.yaml (apply-only; noop).}
|
|
16
|
+
@file = '/etc/puppet/environments/simp/hieradata/hosts/puppet.your.domain.yaml'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def apply
|
|
20
|
+
result = true
|
|
21
|
+
fqdn = @config_items.fetch( 'hostname' ).value
|
|
22
|
+
new_file = File.join( File.dirname( @file ), "#{fqdn}.yaml" )
|
|
23
|
+
say_green 'Moving default <domain>.yaml file' if !@silent
|
|
24
|
+
|
|
25
|
+
if File.exists?(@file)
|
|
26
|
+
if File.exists?( new_file )
|
|
27
|
+
result = false
|
|
28
|
+
diff = `diff #{new_file} #{@file}`
|
|
29
|
+
say_yellow "WARNING: #{File.basename( new_file )} exists, but the content differs from the original system content. Review and consider updating:\n#{diff}" if !diff.empty?
|
|
30
|
+
else
|
|
31
|
+
File.rename( @file, new_file )
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
result = false
|
|
35
|
+
say_yellow "WARNING: file not found: #{@file}"
|
|
36
|
+
end
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|