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 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::AddLdapToHiera < ActionItem
9
+ attr_accessor :dir
10
+
11
+ def initialize
12
+ super
13
+ @key = 'puppet::add_ldap_to_hiera'
14
+ @description = %Q{Adds simp::ldap_server to 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 'Adding simp::ldap_server to the <domain>.yaml file' if !@silent
25
+
26
+ if File.exists?(file)
27
+ success = true
28
+ yaml = File.open(file, "a") do |f|
29
+ f.puts " - 'simp::ldap_server'"
30
+ end
31
+ else
32
+ success = false
33
+ say_yellow "WARNING: file not found: #{file}"
34
+ end
35
+ success
36
+ end
37
+
38
+
39
+ def contains_ldap?( line )
40
+ (line =~ /^\s*-\s+(([a-z_:'"]*::)*(open)*ldap|(open)*ldap[a-z_:'"]*)/m) ? true : false
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
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::AnswersYAMLFileWriter < ActionItem
10
+ attr_accessor :file, :backup_old_file
11
+
12
+ def initialize
13
+ super
14
+ @key = 'yaml::file_writer'
15
+ @description = %Q{Writes Config::Item answers so far to YAML file (apply-only; noop).}
16
+ @file = '/etc/puppet/environments/simp/hieradata/simp_def.yaml'
17
+ @backup_old_file = false
18
+ end
19
+
20
+
21
+ # prints an answers file to an iostream
22
+ def print_answers_yaml( iostream, answers )
23
+ iostream.puts "#======================================="
24
+ iostream.puts "# simp config answers"
25
+ iostream.puts "#"
26
+ iostream.puts "# generated on #{Time.now.to_s}"
27
+ iostream.puts "#---------------------------------------"
28
+ iostream.puts "# you can use these answers to quickly configure subsequent simp installations
29
+ # by running the command:
30
+ #
31
+ # simp config -a /PATH/TO/THIS/FILE
32
+ #
33
+ # simp config will prompt for any missing items
34
+ ".gsub(/^\s+/, '').strip
35
+ iostream.puts "#======================================="
36
+ iostream.puts "---"
37
+ answers.each do |k,v|
38
+ if yaml = v.to_yaml_s # filter out nil results (for ruby 1.8)
39
+ iostream.puts yaml
40
+ iostream.puts
41
+ end
42
+ end
43
+ end
44
+
45
+
46
+ # write a file
47
+ def write_answers_yaml_file( file, answers )
48
+ say_green "Writing answers to: #{file}" if !@silent
49
+ FileUtils.mkdir_p( File.dirname( file ) )
50
+ File.open( file, 'w' ){ |fh| print_answers_yaml( fh, answers ) }
51
+ end
52
+
53
+
54
+ def apply
55
+ write_answers_yaml_file( @file, @config_items ) if @config_items.size > 0
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,39 @@
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::Certificates < ActionItem
10
+ attr_accessor :dirs
11
+ def initialize
12
+ super
13
+ @key = 'certificates'
14
+ @description = %Q{Sets up the cerificates for SIMP on apply. (apply-only; noop)}
15
+ @dirs = {
16
+ :keydist => '/etc/puppet/environments/simp/keydist',
17
+ :fake_ca => '/etc/puppet/environments/simp/FakeCA',
18
+ }
19
+ @die_on_apply_fail = true
20
+ end
21
+
22
+
23
+ def apply
24
+ # Certificate Management
25
+ say_green 'Checking system certificates...' if !@silent
26
+ hostname = @config_items.fetch( 'hostname' ).value
27
+
28
+ if !(
29
+ File.exist?("#{@dirs[:keydist]}/#{hostname}/#{hostname}.pub") &&
30
+ File.exist?("#{@dirs[:fake_ca]}/#{hostname}/#{hostname}.pem")
31
+ )
32
+ say_green "INFO: No certificates were found for '#{hostname}, generating..." if !@silent
33
+ Simp::Cli::Config::Utils.generate_certificates([hostname], @dirs[:fake_ca])
34
+ else
35
+ say_yellow "WARNING: Found existing certificates for #{hostname}, not recreating" if !@silent
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,65 @@
1
+ require 'ipaddr'
2
+ require 'highline/import'
3
+ require File.expand_path( '../item', File.dirname(__FILE__) )
4
+
5
+ module Simp; end
6
+ class Simp::Cli; end
7
+ module Simp::Cli::Config
8
+ class Item::ClientNets < ListItem
9
+ def initialize
10
+ super
11
+ @key = 'client_nets'
12
+ @description = %Q{
13
+ A list of client networks for your systems, in CIDR notation.
14
+ If you need this to be more (or less) restrictive for a given class,
15
+ you can override it in Hiera.}.gsub(/^\s+/, '' )
16
+ @allow_empty_list = false
17
+ end
18
+
19
+ def os_value
20
+ # NOTE: the logic that would normally go here is in recommended_value
21
+ # client_nets is an administrative concept, not an os configuration
22
+ nil
23
+ end
24
+
25
+ # infer base network/CIDR values from IP/netmask
26
+ def recommended_value
27
+ begin
28
+ address = @config_items.fetch('ipaddress').value
29
+ nm = @config_items.fetch('netmask').value
30
+ rescue IndexError => e
31
+ say_yellow("WARNING: #{e}") if !@silent
32
+ return nil
33
+ end
34
+
35
+ # snarfed from:
36
+ # http://stackoverflow.com/questions/1825928/netmask-to-cidr-in-ruby
37
+ subnet = IPAddr.new( nm ).to_i.to_s( 2 ).count('1')
38
+
39
+ mucky_cidr = "#{address}/#{subnet}"
40
+ cidr = "#{ IPAddr.new( mucky_cidr ).to_range.first.to_s}/#{subnet}"
41
+
42
+ [ cidr ]
43
+ end
44
+
45
+ # validate subnet
46
+ def validate_item( net )
47
+ ### warn "'#{net}' doesn't end like a CIDR";
48
+ return false if net !~ %r{/\d+$}
49
+
50
+ ### warn "list item '#{net}' is not in proper CIDR notation";
51
+ return false if net.split('/').size > 2
52
+
53
+ subnet,cidr = net.split('/')
54
+
55
+ # NOTE: if we support IPv6, we should redo netmask & validations
56
+ ### warn "subnet '#{subnet}' is not a valid IP!";
57
+ return false if !((subnet =~ Resolv::IPv4::Regex) || (subnet =~ Resolv::IPv6::Regex))
58
+
59
+ ### warn "/#{cidr} is not a valid CIDR suffix";
60
+ return false if !(cidr.to_i >= 0 && cidr.to_i <= 32)
61
+
62
+ true
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,32 @@
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::CommonRunLevelDefault < Item
9
+ def initialize
10
+ super
11
+ @key = 'common::runlevel'
12
+ @description = %Q{The default system runlevel (1-5).}
13
+ end
14
+
15
+ def validate( x )
16
+ (x.to_s =~ /\A[1-5]\Z/) ? true : false
17
+ end
18
+
19
+ def not_valid_message
20
+ 'Must be a number between 1 and 5'
21
+ end
22
+
23
+ def os_value
24
+ # FIXME: Facter fact
25
+ %x{runlevel | awk '{print $2}'}.strip
26
+ end
27
+
28
+ def recommended_value
29
+ '3'
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,48 @@
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::DNSSearch < ListItem
9
+ attr_accessor :file
10
+ def initialize
11
+ super
12
+ @key = 'dns::search'
13
+ @description = %Q{The DNS domain search string.\nRemember to put these in the appropriate order for your environment!}
14
+ @file = '/etc/resolv.conf'
15
+ end
16
+
17
+ def os_value
18
+ # TODO: make this a custom fact?
19
+ # NOTE: the resolver only uses the last of multiple search declarations
20
+ File.readlines( @file ).select{ |x| x =~ /^search\s+/ }.last.to_s.gsub( /\bsearch\s+/, '').split( /\s+/ )
21
+ end
22
+
23
+ # recommend:
24
+ # - os_value when present, or:
25
+ # - ipaddress when present, or:
26
+ # - a must-change value
27
+ def recommended_value
28
+ os = os_value
29
+ if os.empty?
30
+ if fqdn = @config_items.fetch( 'hostname', nil )
31
+ [fqdn.value.split('.')[1..-1].join('.')]
32
+ else
33
+ ['domain.name (change this)']
34
+ end
35
+ else
36
+ os
37
+ end
38
+ end
39
+
40
+ # Each item must be a valid dns domain
41
+ # TODO: def validate should notice if the search string will contain > 6
42
+ # items or 256 chars
43
+ def validate_item item
44
+ # return false if !fqdn.is_a? String
45
+ Simp::Cli::Config::Utils.validate_fqdn item
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,57 @@
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::DNSServers < ListItem
9
+ attr_accessor :file
10
+ def initialize
11
+ super
12
+ @key = 'dns::servers'
13
+ @description = %Q{A list of DNS servers for the managed hosts.
14
+
15
+ If the first entry of this list is set to '127.0.0.1', then
16
+ all clients will configure themselves as caching DNS servers
17
+ pointing to the other entries in the list.
18
+
19
+ If you have a system that's including the 'named' class and
20
+ is *not* in this list, then you'll need to set a variable at
21
+ the top of that node entry called $named_server to 'true'.
22
+ This will get around the convenience logic that was put in
23
+ place to handle the caching entries and will not attempt to
24
+ convert your system to a caching DNS server. You'll know
25
+ that you have this situation if you end up with a duplicate
26
+ definition for File['/etc/named.conf'].}.gsub(/^ +/, '')
27
+ @file = '/etc/resolv.conf'
28
+ end
29
+
30
+ def os_value
31
+ # TODO: make this a custom fact?
32
+ File.readlines( @file ).select{ |x| x =~ /^nameserver\s+/ }.map{ |x| x.gsub( /nameserver\s+(.*)\s*/, '\\1' ) }
33
+ end
34
+
35
+ # recommend:
36
+ # - os_value when present, or:
37
+ # - ipaddress when present, or:
38
+ # - a must-change value
39
+ def recommended_value
40
+ os = os_value
41
+ if os.empty?
42
+ if ip = @config_items.fetch( 'ipaddress', nil )
43
+ [ip.value]
44
+ else
45
+ ['8.8.8.8 (change this)']
46
+ end
47
+ else
48
+ os
49
+ end
50
+ end
51
+
52
+ # Each DNS server should be a valid IP address
53
+ def validate_item item
54
+ Simp::Cli::Config::Utils.validate_ip item
55
+ end
56
+ end
57
+ 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::FailoverLogServers < ListItem
10
+ def initialize
11
+ super
12
+ @key = 'failover_log_servers'
13
+ @description = 'Failover log server(s) in case your log servers(s) fail.'
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,32 @@
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::Gateway < Item
8
+ def initialize
9
+ super
10
+ @key = 'gateway'
11
+ @description = 'The default gateway.'
12
+ @__warning = false
13
+ end
14
+
15
+
16
+ # FIXME: make this a custom Fact?
17
+ def os_value
18
+ `ip route show` =~ /default\s*via\s*(.*)\s*dev/
19
+ (($1 && $1.strip) || nil)
20
+ end
21
+
22
+
23
+ # Always recommend the default Gateway
24
+ # TODO IDEA: recommend the primary nic's gateway?
25
+ def recommended_value; os_value; end
26
+
27
+
28
+ def validate( x )
29
+ Simp::Cli::Config::Utils.validate_ip x
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,51 @@
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
+
8
+
9
+ # NOTE: EL used GRUB 0.9 up through EL6. EL7 moved to Grub 2.0
10
+ # NOTE: The two versions of GRUB use completely different configurations (files, encryption commands, etc)
11
+ module Simp::Cli::Config
12
+ class Item::GrubPassword < PasswordItem
13
+ include Simp::Cli::Config::SafeApplying
14
+
15
+ def initialize
16
+ super
17
+ @key = 'grub::password'
18
+ @description = %Q{The password to access GRUB}
19
+ end
20
+
21
+
22
+ def validate string
23
+ !string.to_s.strip.empty? && super
24
+ end
25
+
26
+
27
+ def encrypt string
28
+ result = nil
29
+ password = string
30
+ if Facter.value('lsbmajdistrelease') > '6'
31
+ result = `grub2-mkpasswd-pbkdf2 <<EOM\n#{password}\n#{password}\nEOM`.split.last
32
+ else
33
+ require 'digest/sha2'
34
+ salt = rand(36**8).to_s(36)
35
+ result = password.crypt("$6$" + salt)
36
+ end
37
+ result
38
+ end
39
+
40
+
41
+ def apply
42
+ if Facter.value('lsbmajdistrelease') > "6" then
43
+ # TODO: beg team hercules to make a augeas provider for grub2 passwords?
44
+ `sed -i 's/password_pbkdf2 root.*$/password_pbkdf2 root #{@value}/' /etc/grub.d/01_users`
45
+ `grub2-mkconfig -o /etc/grub2.cfg`
46
+ else
47
+ `sed -i '/password/ c\password --encrypted #{@value}' /boot/grub/grub.conf`
48
+ end
49
+ end
50
+ end
51
+ end