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.
Files changed (150) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE +27 -0
  3. data/README.md +48 -0
  4. data/Rakefile +142 -0
  5. data/bin/simp +5 -0
  6. data/lib/simp/cli.rb +88 -0
  7. data/lib/simp/cli/commands/bootstrap.rb +275 -0
  8. data/lib/simp/cli/commands/check.rb +163 -0
  9. data/lib/simp/cli/commands/cleancerts.rb +114 -0
  10. data/lib/simp/cli/commands/config.rb +235 -0
  11. data/lib/simp/cli/commands/doc.rb +14 -0
  12. data/lib/simp/cli/commands/passgen.rb +128 -0
  13. data/lib/simp/cli/commands/puppeteval.rb +82 -0
  14. data/lib/simp/cli/commands/runpuppet.rb +95 -0
  15. data/lib/simp/cli/config/item.rb +456 -0
  16. data/lib/simp/cli/config/item/add_ldap_to_hiera.rb +43 -0
  17. data/lib/simp/cli/config/item/answers_yaml_file_writer.rb +58 -0
  18. data/lib/simp/cli/config/item/certificates.rb +39 -0
  19. data/lib/simp/cli/config/item/client_nets.rb +65 -0
  20. data/lib/simp/cli/config/item/common_runlevel_default.rb +32 -0
  21. data/lib/simp/cli/config/item/dns_search.rb +48 -0
  22. data/lib/simp/cli/config/item/dns_servers.rb +57 -0
  23. data/lib/simp/cli/config/item/failover_log_servers.rb +27 -0
  24. data/lib/simp/cli/config/item/gateway.rb +32 -0
  25. data/lib/simp/cli/config/item/grub_password.rb +51 -0
  26. data/lib/simp/cli/config/item/hostname.rb +24 -0
  27. data/lib/simp/cli/config/item/hostname_conf.rb +48 -0
  28. data/lib/simp/cli/config/item/ipaddress.rb +46 -0
  29. data/lib/simp/cli/config/item/is_master_yum_server.rb +23 -0
  30. data/lib/simp/cli/config/item/ldap_base_dn.rb +38 -0
  31. data/lib/simp/cli/config/item/ldap_bind_dn.rb +34 -0
  32. data/lib/simp/cli/config/item/ldap_bind_hash.rb +28 -0
  33. data/lib/simp/cli/config/item/ldap_bind_pw.rb +24 -0
  34. data/lib/simp/cli/config/item/ldap_master.rb +33 -0
  35. data/lib/simp/cli/config/item/ldap_root_dn.rb +42 -0
  36. data/lib/simp/cli/config/item/ldap_root_hash.rb +35 -0
  37. data/lib/simp/cli/config/item/ldap_sync_dn.rb +24 -0
  38. data/lib/simp/cli/config/item/ldap_sync_hash.rb +28 -0
  39. data/lib/simp/cli/config/item/ldap_sync_pw.rb +26 -0
  40. data/lib/simp/cli/config/item/ldap_uri.rb +43 -0
  41. data/lib/simp/cli/config/item/log_servers.rb +27 -0
  42. data/lib/simp/cli/config/item/netmask.rb +39 -0
  43. data/lib/simp/cli/config/item/network_conf.rb +63 -0
  44. data/lib/simp/cli/config/item/network_dhcp.rb +27 -0
  45. data/lib/simp/cli/config/item/network_interface.rb +41 -0
  46. data/lib/simp/cli/config/item/network_setup_nic.rb +28 -0
  47. data/lib/simp/cli/config/item/ntp_servers.rb +69 -0
  48. data/lib/simp/cli/config/item/puppet_autosign.rb +66 -0
  49. data/lib/simp/cli/config/item/puppet_ca.rb +31 -0
  50. data/lib/simp/cli/config/item/puppet_ca_port.rb +28 -0
  51. data/lib/simp/cli/config/item/puppet_conf.rb +98 -0
  52. data/lib/simp/cli/config/item/puppet_fileserver.rb +104 -0
  53. data/lib/simp/cli/config/item/puppet_hosts_entry.rb +44 -0
  54. data/lib/simp/cli/config/item/puppet_server.rb +30 -0
  55. data/lib/simp/cli/config/item/puppet_server_ip.rb +25 -0
  56. data/lib/simp/cli/config/item/puppetdb_port.rb +25 -0
  57. data/lib/simp/cli/config/item/puppetdb_server.rb +26 -0
  58. data/lib/simp/cli/config/item/remove_ldap_from_hiera.rb +47 -0
  59. data/lib/simp/cli/config/item/rename_fqdn_yaml.rb +40 -0
  60. data/lib/simp/cli/config/item/rsync_base.rb +37 -0
  61. data/lib/simp/cli/config/item/rsync_server.rb +44 -0
  62. data/lib/simp/cli/config/item/rsync_timeout.rb +26 -0
  63. data/lib/simp/cli/config/item/set_grub_password.rb +19 -0
  64. data/lib/simp/cli/config/item/simp_yum_servers.rb +30 -0
  65. data/lib/simp/cli/config/item/use_auditd.rb +19 -0
  66. data/lib/simp/cli/config/item/use_fips.rb +46 -0
  67. data/lib/simp/cli/config/item/use_iptables.rb +22 -0
  68. data/lib/simp/cli/config/item/use_ldap.rb +19 -0
  69. data/lib/simp/cli/config/item/use_selinux.rb +32 -0
  70. data/lib/simp/cli/config/item/yum_repositories.rb +75 -0
  71. data/lib/simp/cli/config/item_list_factory.rb +236 -0
  72. data/lib/simp/cli/config/questionnaire.rb +86 -0
  73. data/lib/simp/cli/config/utils.rb +128 -0
  74. data/lib/simp/cli/lib/utils.rb +114 -0
  75. data/lib/simp/simp.rb +77 -0
  76. data/spec/lib/simp/cli/commands/config_spec.rb +42 -0
  77. data/spec/lib/simp/cli/config/item/add_ldap_to_hiera_spec.rb +58 -0
  78. data/spec/lib/simp/cli/config/item/answers_yaml_file_writer_spec.rb +86 -0
  79. data/spec/lib/simp/cli/config/item/certificates_spec.rb +50 -0
  80. data/spec/lib/simp/cli/config/item/client_nets_spec.rb +66 -0
  81. data/spec/lib/simp/cli/config/item/common_runlevel_default_spec.rb +27 -0
  82. data/spec/lib/simp/cli/config/item/dns_search_spec.rb +74 -0
  83. data/spec/lib/simp/cli/config/item/dns_servers_spec.rb +76 -0
  84. data/spec/lib/simp/cli/config/item/failover_log_servers_spec.rb +49 -0
  85. data/spec/lib/simp/cli/config/item/files/FakeCA/cacertkey +1 -0
  86. data/spec/lib/simp/cli/config/item/files/FakeCA/gencerts_nopass.sh +10 -0
  87. data/spec/lib/simp/cli/config/item/files/autosign.conf.new +11 -0
  88. data/spec/lib/simp/cli/config/item/files/autosign.conf.used +15 -0
  89. data/spec/lib/simp/cli/config/item/files/fileserver.conf +41 -0
  90. data/spec/lib/simp/cli/config/item/files/hosts +2 -0
  91. data/spec/lib/simp/cli/config/item/files/hosts.old_puppet_entry +3 -0
  92. data/spec/lib/simp/cli/config/item/files/puppet.conf +25 -0
  93. data/spec/lib/simp/cli/config/item/files/puppet.your.domain.yaml +21 -0
  94. data/spec/lib/simp/cli/config/item/files/resolv.conf__multiple +10 -0
  95. data/spec/lib/simp/cli/config/item/files/resolv.conf__single +4 -0
  96. data/spec/lib/simp/cli/config/item/files/rsyncd.conf +225 -0
  97. data/spec/lib/simp/cli/config/item/gateway_spec.rb +23 -0
  98. data/spec/lib/simp/cli/config/item/grub_password_spec.rb +24 -0
  99. data/spec/lib/simp/cli/config/item/hostname_conf_spec.rb +27 -0
  100. data/spec/lib/simp/cli/config/item/hostname_spec.rb +22 -0
  101. data/spec/lib/simp/cli/config/item/ipaddress_spec.rb +40 -0
  102. data/spec/lib/simp/cli/config/item/is_master_yum_server_spec.rb +29 -0
  103. data/spec/lib/simp/cli/config/item/ldap_base_dn_spec.rb +23 -0
  104. data/spec/lib/simp/cli/config/item/ldap_bind_dn_spec.rb +23 -0
  105. data/spec/lib/simp/cli/config/item/ldap_bind_hash_spec.rb +23 -0
  106. data/spec/lib/simp/cli/config/item/ldap_bind_pw_spec.rb +21 -0
  107. data/spec/lib/simp/cli/config/item/ldap_master_spec.rb +37 -0
  108. data/spec/lib/simp/cli/config/item/ldap_root_dn_spec.rb +23 -0
  109. data/spec/lib/simp/cli/config/item/ldap_root_hash_spec.rb +23 -0
  110. data/spec/lib/simp/cli/config/item/ldap_sync_dn_spec.rb +22 -0
  111. data/spec/lib/simp/cli/config/item/ldap_sync_hash_spec.rb +23 -0
  112. data/spec/lib/simp/cli/config/item/ldap_sync_pw_spec.rb +21 -0
  113. data/spec/lib/simp/cli/config/item/ldap_uri_spec.rb +32 -0
  114. data/spec/lib/simp/cli/config/item/log_servers_spec.rb +49 -0
  115. data/spec/lib/simp/cli/config/item/netmask_spec.rb +28 -0
  116. data/spec/lib/simp/cli/config/item/network_conf_spec.rb +63 -0
  117. data/spec/lib/simp/cli/config/item/network_dhcp_spec.rb +11 -0
  118. data/spec/lib/simp/cli/config/item/network_interface_spec.rb +26 -0
  119. data/spec/lib/simp/cli/config/item/network_setup_nic_spec.rb +29 -0
  120. data/spec/lib/simp/cli/config/item/ntp_servers_spec.rb +43 -0
  121. data/spec/lib/simp/cli/config/item/puppet_autosign_spec.rb +55 -0
  122. data/spec/lib/simp/cli/config/item/puppet_ca_port_spec.rb +23 -0
  123. data/spec/lib/simp/cli/config/item/puppet_ca_spec.rb +22 -0
  124. data/spec/lib/simp/cli/config/item/puppet_conf_spec.rb +110 -0
  125. data/spec/lib/simp/cli/config/item/puppet_fileserver_spec.rb +53 -0
  126. data/spec/lib/simp/cli/config/item/puppet_hosts_entry_spec.rb +85 -0
  127. data/spec/lib/simp/cli/config/item/puppet_server_ip_spec.rb +24 -0
  128. data/spec/lib/simp/cli/config/item/puppet_server_spec.rb +22 -0
  129. data/spec/lib/simp/cli/config/item/puppetdb_port_spec.rb +25 -0
  130. data/spec/lib/simp/cli/config/item/puppetdb_server_spec.rb +25 -0
  131. data/spec/lib/simp/cli/config/item/remove_ldap_from_hiera_spec.rb +58 -0
  132. data/spec/lib/simp/cli/config/item/rename_fqdn_yaml_spec.rb +63 -0
  133. data/spec/lib/simp/cli/config/item/rsync_base_spec.rb +28 -0
  134. data/spec/lib/simp/cli/config/item/rsync_server_spec.rb +41 -0
  135. data/spec/lib/simp/cli/config/item/rsync_timeout_spec.rb +21 -0
  136. data/spec/lib/simp/cli/config/item/set_grub_password_spec.rb +29 -0
  137. data/spec/lib/simp/cli/config/item/simp_yum_servers_spec.rb +41 -0
  138. data/spec/lib/simp/cli/config/item/spec_helper.rb +22 -0
  139. data/spec/lib/simp/cli/config/item/use_auditd_spec.rb +29 -0
  140. data/spec/lib/simp/cli/config/item/use_fips_spec.rb +29 -0
  141. data/spec/lib/simp/cli/config/item/use_iptables_spec.rb +29 -0
  142. data/spec/lib/simp/cli/config/item/use_ldap_spec.rb +29 -0
  143. data/spec/lib/simp/cli/config/item/use_selinux_spec.rb +24 -0
  144. data/spec/lib/simp/cli/config/item/yum_repositories_spec.rb +94 -0
  145. data/spec/lib/simp/cli/config/item_spec.rb +106 -0
  146. data/spec/lib/simp/cli/config/spec_helper.rb +1 -0
  147. data/spec/lib/simp/cli/config/utils_spec.rb +131 -0
  148. data/spec/lib/simp/cli/spec_helper.rb +1 -0
  149. data/spec/spec_helper.rb +91 -0
  150. metadata +391 -0
@@ -0,0 +1,43 @@
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
+ # FIXME: what is this for?
10
+ class Item::LdapUri < ListItem
11
+ def initialize
12
+ super
13
+ @key = 'ldap::uri'
14
+ @description = %Q{List of OpenLDAP servers in URI form (ldap://server)}
15
+ end
16
+
17
+
18
+ def os_value
19
+ values = `grep URI /etc/openldap/ldap.conf`.split("\n").map do |line|
20
+ line =~ /^\s*URI\s+(.+)\s*/
21
+ $1
22
+ end.compact
23
+ values
24
+ end
25
+
26
+
27
+ def recommended_value
28
+ if item = @config_items.fetch( 'hostname', nil )
29
+ [ "ldap://#{item.value}" ]
30
+ end
31
+ end
32
+
33
+
34
+ def validate_item item
35
+ ( item =~ %r{^ldap://.+} ) ? true : false &&
36
+ (
37
+ Simp::Cli::Config::Utils.validate_hostname( item ) ||
38
+ Simp::Cli::Config::Utils.validate_fqdn( item ) ||
39
+ Simp::Cli::Config::Utils.validate_ip( item )
40
+ )
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
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::LogServers < ListItem
10
+ def initialize
11
+ super
12
+ @key = 'log_servers'
13
+ @description = %Q{Your log server(s). Only use hostnames here if at all possible.}
14
+ @allow_empty_list = true
15
+ end
16
+
17
+ def os_value
18
+ nil
19
+ end
20
+
21
+ def validate_item item
22
+ ( Simp::Cli::Config::Utils.validate_hostname( item ) ||
23
+ Simp::Cli::Config::Utils.validate_fqdn( item ) ||
24
+ Simp::Cli::Config::Utils.validate_ip( item ) )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
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::Netmask < Item
9
+ def initialize
10
+ super
11
+ @key = 'netmask'
12
+ @description = %q{The netmask of the system.}
13
+ @__warning = false
14
+ end
15
+
16
+ def validate( x )
17
+ Simp::Cli::Config::Utils.validate_netmask x
18
+ end
19
+
20
+ # TODO: comment upon the hell-logic below
21
+ # TODO: possibly refactor ip and netmask os_value into shared parent
22
+ def os_value
23
+ netmask = nil
24
+ nic = @config_items.fetch('network::interface').value
25
+ if nic || @fact
26
+ @fact = @fact || "netmask_#{nic}"
27
+ netmask = super
28
+ if netmask.nil? and !@__warning
29
+ warning = "WARNING: #{@key}: No Netmask found for NIC #{nic}"
30
+ say "<%= color(%q{#{warning}}, YELLOW) %>\n"
31
+ @__warning = true
32
+ end
33
+ end
34
+ netmask
35
+ end
36
+
37
+ def recommended_value; os_value; end
38
+ end
39
+ end
@@ -0,0 +1,63 @@
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::NetworkConf < ActionItem
9
+ def initialize
10
+ super
11
+ @key = 'network::conf'
12
+ @description = 'action item; configures network interfaces'
13
+ @die_on_apply_fail = true
14
+ end
15
+
16
+ def apply
17
+ ci = {}
18
+ cmd = nil
19
+
20
+ dhcp = @config_items.fetch( 'dhcp' ).value
21
+ # BOOTPROTO=none is valid to spec; BOOTPROTO=static isn't
22
+ bootproto = (dhcp == 'static') ? 'none' : dhcp
23
+ interface = @config_items.fetch( 'network::interface' ).value
24
+
25
+ # apply the interface useing the SIMP classes
26
+ # NOTE: the "FACTER_ipaddress=XXX" helps puppet avoid a fatal error that
27
+ # occurs in the core ipaddress fact on offline systems.
28
+ cmd = %Q@FACTER_ipaddress=XXX puppet apply -e "network::add_eth{'#{interface}': bootproto => '#{bootproto}', onboot => 'yes'@
29
+
30
+ if bootproto == 'none'
31
+ ipaddress = @config_items.fetch( 'ipaddress' ).value
32
+ hostname = @config_items.fetch( 'hostname' ).value
33
+ netmask = @config_items.fetch( 'netmask' ).value
34
+ gateway = @config_items.fetch( 'gateway' ).value
35
+ dns_search = @config_items.fetch( 'dns::search' ).value
36
+ dns_servers = @config_items.fetch( 'dns::servers').value
37
+
38
+ resolv_domain = hostname.split('.')[1..-1].join('.')
39
+ cmd += %Q{, }
40
+ cmd += %Q@ipaddr => '#{ipaddress}', @
41
+ cmd += %Q@netmask => '#{netmask}', @
42
+ cmd += %Q@gateway => '#{gateway}' } @
43
+ cmd += %Q@class{ 'common::resolv': @
44
+ cmd += %Q@resolv_domain => '#{resolv_domain}', @
45
+ cmd += %Q@nameservers => #{ format_puppet_array( dns_servers ) }, @
46
+ cmd += %Q@search => #{ format_puppet_array( dns_search ) }, @
47
+ cmd += %Q@named_autoconf => false, @
48
+ end
49
+ cmd += %Q@}"@
50
+ # TODO: maybe good ideas
51
+ # - set $::domain with FACTER_domain=
52
+ # - set comon::resolv{ named_autofonf => false
53
+
54
+ puts cmd unless @silent
55
+ %x{#{cmd}}
56
+ end
57
+
58
+ def format_puppet_array v
59
+ v = [v] if v.kind_of? String
60
+ "['#{v.join "','"}']"
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,27 @@
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::DHCP < Item
9
+ def initialize
10
+ super
11
+ @key = 'dhcp'
12
+ @description = %q{Whether or not to use DHCP to set up your network ("static" or "dhcp")}
13
+ end
14
+
15
+ def recommended_value
16
+ 'static' # a puppet master is always recommended to be static.
17
+ end
18
+
19
+ def validate( x )
20
+ return ['dhcp', 'static' ].include?( x.to_s.downcase )
21
+ end
22
+
23
+ def not_valid_message
24
+ 'Valid answers are "static" or "dhcp"'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
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
+
9
+ class Item::NetworkInterface < Item
10
+ def initialize
11
+ super
12
+ @key = 'network::interface'
13
+ @description = 'The network interface to use to connect to the network.'
14
+ end
15
+
16
+ # try to guess which NIC is likely to be used
17
+ # TODO IDEA: also use Facter to prefer NICs that already have IPs
18
+ def recommended_value
19
+ devices = acceptable_values
20
+ (
21
+ devices.select{|x| x.match(/^br/)}.first ||
22
+ devices.select{|x| x.match(/^eth/)}.first ||
23
+ devices.select{|x| x.match(/^em/)}.first ||
24
+ devices.first
25
+ )
26
+ end
27
+
28
+ def validate( x )
29
+ acceptable_values.include?( x )
30
+ end
31
+
32
+ def not_valid_message
33
+ "Acceptable values: \n" + acceptable_values.map{ |x| " #{x}" }.join("\n")
34
+ end
35
+
36
+ # helper method; provides a list of available NICs
37
+ def acceptable_values
38
+ Facter.value('interfaces').split(',').delete_if{|x| x == 'lo'}.sort
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
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::SetupNIC < YesNoItem
9
+ def initialize
10
+ super
11
+ @key = 'network::setup_nic'
12
+ @description = %Q{Do you want to activate this NIC now?}
13
+ end
14
+
15
+ def recommended_value
16
+ os_value || 'yes'
17
+ end
18
+
19
+ def query_ask
20
+ # TODO: check, then
21
+ # The NIC does not currently have an IP, Netmask, or Gateway
22
+ nic = @config_items.fetch('network::interface').value
23
+ # @description.gsub( 'this NIC'
24
+ super
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,69 @@
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::NTPServers < ListItem
10
+ def initialize
11
+ super
12
+ @key = 'ntpd::servers'
13
+ @warnings = {
14
+ :no_ntp => "A consistent time source is critical to your systems' security.",
15
+ :warning_hw_clocks => "DO NOT run multiple production systems using individual hardware clocks!",
16
+ }
17
+ @description = "Your network's NTP time servers.\n\n#{@warnings.values.join("\n")}"
18
+ @allow_empty_list = true
19
+ end
20
+
21
+ def description
22
+ extra = ''
23
+ if @config_items.key? 'gateway'
24
+ gateway = @config_items.fetch('gateway').value
25
+ extra = "\nFor many networks, the default gateway (#{gateway}) provides an NTP server."
26
+ end
27
+ "#{@description}#{extra}"
28
+ end
29
+
30
+ def os_value( file='/etc/ntp/ntpservers' )
31
+ # TODO: make this a custom fact?
32
+ # TODO: is /etc/ntp/ntpservers being used in recent versions of SIMP?
33
+ servers = []
34
+ if File.readable? file
35
+ File.readlines( file ).map do |line|
36
+ line.strip!
37
+ if line !~ /^#/
38
+ servers << line
39
+ else
40
+ nil
41
+ end
42
+ end.compact
43
+ end
44
+ servers
45
+ end
46
+
47
+ def recommended_value
48
+ if (!os_value.empty?) && (os_value.first !~ /^127\./)
49
+ os_value
50
+ else
51
+ nil
52
+ end
53
+ end
54
+
55
+ # allow empty NTP servers, but reiterate warning because it's important.
56
+ def validate list
57
+ if !@silent && (list.is_a?(Array) || list.is_a?(String)) && list.empty?
58
+ say_red( "IMPORTANT: #{@warnings.fetch(:no_ntp)}" )
59
+ sleep 3 # TODO: should there be a standard timeout for Item delays?
60
+ end
61
+ super
62
+ end
63
+
64
+ def validate_item item
65
+ ( Simp::Cli::Config::Utils.validate_ip( item ) ||
66
+ Simp::Cli::Config::Utils.validate_fqdn( item ) )
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,66 @@
1
+ require 'highline/import'
2
+ require File.expand_path( '../item', File.dirname(__FILE__) )
3
+ require File.expand_path( '../utils', File.dirname(__FILE__) )
4
+ module Simp; end
5
+ class Simp::Cli; end
6
+ module Simp::Cli::Config
7
+ class Item::PuppetAutosign < ActionItem
8
+ attr_accessor :file
9
+ def initialize
10
+ super
11
+ @key = 'puppet::autosign'
12
+ @description = %Q{By default, the only host eligible for autosign is the puppet master.}
13
+ @file = '/etc/puppet/autosign.conf'
14
+ end
15
+
16
+ def os_value
17
+ # TODO: make this a custom fact?
18
+ values = Array.new
19
+ File.readable?(@file) &&
20
+ File.readlines(@file).each do |line|
21
+ next if line =~ /^(\#|\s*$)/
22
+
23
+ # if we encounter 'puppet.your.domain' (the default value from a
24
+ # fresh simp-bootstrap RPM), infer this is a freshly installed system
25
+ # with no legitimate autosign entries.
26
+ if line =~ /^puppet.your.domain/
27
+ values = []
28
+ break
29
+ end
30
+ values << line.strip
31
+ end
32
+ if values.size == 0
33
+ nil
34
+ else
35
+ values
36
+ end
37
+ end
38
+
39
+ def recommended_value
40
+ item = os_value
41
+ if !item
42
+ item = @config_items.fetch( 'hostname', nil )
43
+ item = [ item.value ] if item
44
+ end
45
+ item
46
+ end
47
+
48
+ def apply
49
+ entries = recommended_value
50
+ say_green "Updating #{@file}..." if !@silent
51
+ File.open(@file, 'w') do |file|
52
+ file.puts "# You should place any hostnames/domains here that you wish to autosign.\n" +
53
+ "# The most security-conscious method is to list each individual hostname:\n" +
54
+ "# hosta.your.domain\n" +
55
+ "# hostb.your.domain\n" +
56
+ "#\n" +
57
+ "# Wildcard domains work, but absolutely should NOT be used unless you fully\n" +
58
+ "# trust your network.\n" +
59
+ "# *.your.domain\n\n"
60
+ entries.each do |entry|
61
+ file.puts(entry)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,31 @@
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::PuppetCA < Item
10
+ def initialize
11
+ super
12
+ @key = 'puppet::ca'
13
+ @description = 'The Puppet Certificate Authority'
14
+ end
15
+
16
+ def os_value
17
+ Puppet.settings.setting( 'ca_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
+ Simp::Cli::Config::Utils.validate_ip( x )
24
+ end
25
+
26
+ def recommended_value
27
+ item = @config_items.fetch( 'hostname', nil )
28
+ item.value if item
29
+ end
30
+ end
31
+ end