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,37 @@
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::RsyncBase < Item
9
+ def initialize
10
+ super
11
+ @key = 'rsync::base'
12
+ @description = <<-EOF.gsub(/^ {8}/,'')
13
+ Several modules use rsync as a means of pulling down large
14
+ collections of files. This provides a single point of configuration
15
+ for the system defaults.
16
+
17
+ Individual modules can be overridden as required.
18
+ EOF
19
+ if Facter.value('lsbmajdistrelease') < '7' then
20
+ @base_dir = '/srv/rsync'
21
+ else
22
+ @base_dir = File.exists?( '/var/simp/' ) ? '/var/simp/rsync' : '/srv/simp/rsync'
23
+ @base_dir = "#{@base_dir}/%{::operatingsystem}/%{::lsbmajdistrelease}"
24
+ end
25
+ end
26
+
27
+ def os_value; nil; end
28
+
29
+ def validate( x )
30
+ x =~ %r{^/} ? true : false
31
+ end
32
+
33
+ def recommended_value
34
+ "#{@base_dir}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
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::RsyncServer < Item
9
+ attr_accessor :file
10
+ def initialize
11
+ super
12
+ @key = 'rsync::server'
13
+ @description = 'rsync server (usually the primary puppet master)'
14
+ @__warning = false
15
+ @file = '/etc/rsyncd.conf'
16
+ @skip_query = true
17
+ end
18
+
19
+ def os_value
20
+ if File.readable?(@file)
21
+ res = File.readlines(@file).grep( /address\s*=/ ){|x| x.split('=').last.strip}
22
+ res.empty? ? nil : res.first
23
+ else
24
+ # only show the FIRST warning
25
+ if !@__warning
26
+ warning = "WARNING: cannot read #{file}"
27
+ say "<%= color(%q{#{warning}}, YELLOW) %>\n" unless @silent
28
+ @__warning = true
29
+ end
30
+ nil
31
+ end
32
+ end
33
+
34
+ def recommended_value
35
+ os_value || '127.0.0.1'
36
+ end
37
+
38
+ def validate item
39
+ ( Simp::Cli::Config::Utils.validate_ip( item ) ||
40
+ Simp::Cli::Config::Utils.validate_fqdn( item ) ||
41
+ Simp::Cli::Config::Utils.validate_hostname( item ) )
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
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::RsyncTimeout < Item
9
+ def initialize
10
+ super
11
+ @key = 'rsync::timeout'
12
+ @description = 'maximum rsync timeout in seconds. 0 = no timeout'
13
+ @skip_query = true
14
+ end
15
+
16
+ def os_value; nil; end
17
+
18
+ def validate( x )
19
+ x.to_s =~ %r{^\d+} ? true : false
20
+ end
21
+
22
+ def recommended_value
23
+ '1'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
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::SetGrubPassword < YesNoItem
9
+ def initialize
10
+ super
11
+ @key = 'set_grub_password'
12
+ @description = %Q{Whether or not to set the GRUB password on this system.}
13
+ end
14
+
15
+ def recommended_value
16
+ os_value || 'yes'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
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::SimpYumServers < ListItem
10
+ def initialize
11
+ super
12
+ @key = 'simp::yum::servers'
13
+ @description = %Q{Your SIMP yum server(s).}
14
+ @allow_empty_list = true
15
+ end
16
+
17
+ def recommended_value
18
+ ["%{hiera('puppet::server')}"]
19
+ end
20
+
21
+ def validate_item item
22
+ (
23
+ Simp::Cli::Config::Utils.validate_hiera_lookup( item ) ||
24
+ Simp::Cli::Config::Utils.validate_hostname( item ) ||
25
+ Simp::Cli::Config::Utils.validate_fqdn( item ) ||
26
+ Simp::Cli::Config::Utils.validate_ip( item )
27
+ )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
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::UseAuditd < YesNoItem
9
+ def initialize
10
+ super
11
+ @key = 'use_auditd'
12
+ @description = %q{Whether or not to use auditd on this system.}
13
+ end
14
+
15
+ def recommended_value
16
+ os_value || 'yes'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,46 @@
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::UseFips < YesNoItem
9
+ include Simp::Cli::Config::SafeApplying
10
+
11
+ def initialize
12
+ super
13
+ @key = 'use_fips'
14
+ @description = %q{Enable FIPS mode on this system.
15
+
16
+ FIPS mode enforces strict compliance with FIPS-140-2. All core SIMP modules
17
+ can support this configuration.
18
+
19
+ IMPORTANT: Be sure you know the security tradeoffs of FIPS-140-2 compliance.
20
+ FIPS mode disables the use of MD5 and may require weaker ciphers or key lengths
21
+ than your security policies allow.
22
+ }
23
+ @allow_user_apply = true
24
+ end
25
+
26
+ def os_value
27
+ Facter.value('fips_enabled') ? 'yes' : 'no'
28
+ end
29
+
30
+ def recommended_value
31
+ os_value || 'yes'
32
+ end
33
+
34
+ def apply
35
+ if @value
36
+ # This is a one-off prep item needed to handle Puppet certs w/FIPS mode
37
+ cmd = %q(puppet config set digest_algorithm sha256)
38
+ puts cmd unless @silent
39
+ %x{#{cmd}}
40
+ else
41
+ puts 'not using FIPS mode: noop'
42
+ true # we applied nothing, successfully!
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
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::UseIPtables < YesNoItem
9
+ def initialize
10
+ super
11
+ @key = 'use_iptables'
12
+ @description = %Q{Whether or not to use iptables on this system.
13
+
14
+ If there is code that calls the IPTables native type directly, this option may
15
+ not function properly. We are looking into solutions for this issue.}
16
+ end
17
+
18
+ def recommended_value
19
+ os_value || 'yes'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
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::UseLdap < YesNoItem
9
+ def initialize
10
+ super
11
+ @key = 'use_ldap'
12
+ @description = %Q{Whether or not to use LDAP on this system.\nIf you disable this, modules will not attempt to use LDAP where possible.}
13
+ end
14
+
15
+ def recommended_value
16
+ os_value || 'yes'
17
+ end
18
+ end
19
+ 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::UseSELinux < Item
9
+ def initialize
10
+ super
11
+ @key = 'selinux::ensure'
12
+ @fact = 'selinux_current_mode'
13
+ @description = %Q{SELinux is good.
14
+
15
+ Not all modules are compatible with SELinux in enforcing mode but the core
16
+ SIMP modules are. You should not take this below 'permissive' unless it is
17
+ truly necessary.}
18
+ end
19
+
20
+ def validate( x )
21
+ (x.to_s =~ /permissive|disabled|enforcing/i ) ? true : false
22
+ end
23
+
24
+ def not_valid_message
25
+ 'Must be "enforcing," "permissive," or "disabled" (not recommended)'
26
+ end
27
+
28
+ def recommended_value
29
+ os_value || 'enforcing'
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,75 @@
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::YumRepositories < ActionItem
10
+
11
+ attr_accessor :www_yum_dir, :yum_repos_d, :yaml_file
12
+ def initialize
13
+ super
14
+ @key = 'yum::repositories'
15
+ @description = %Q{Sets up the yum repositores for SIMP on apply. (apply-only; noop)}
16
+ @www_yum_dir = File.exists?( '/var/www/yum/') ? '/var/www/yum' : '/srv/www/yum'
17
+ @yum_repos_d = '/etc/yum.repos.d'
18
+ @yaml_file = '/etc/puppet/environments/simp/hieradata/hosts/puppet.your.domain.yaml'
19
+ end
20
+
21
+ def apply
22
+ result = true
23
+
24
+ # set up yum repos
25
+ say_green 'Updating YUM Updates Repositories (NOTE: This may take some time)' if !@silent
26
+ yumpath = File.join( @www_yum_dir,
27
+ Facter.value('operatingsystem'),
28
+ Facter.value('operatingsystemrelease'),
29
+ Facter.value('architecture')
30
+ )
31
+ begin
32
+ Dir.chdir(yumpath) do
33
+ FileUtils.mkdir('Updates') unless File.directory?('Updates')
34
+ Dir.chdir('Updates') do
35
+ system( %q(find .. -type f -name '*.rpm' -exec ln -sf {} \\;) )
36
+ cmd = 'createrepo -qqq -p --update .'
37
+ if @silent
38
+ cmd << ' &> /dev/null'
39
+ else
40
+ puts cmd
41
+ end
42
+ system(cmd)
43
+ raise RuntimeError "'#{cmd}' failed in #{Dir.pwd}" unless ($?.nil? || $?.success?)
44
+ end
45
+ end
46
+ system("chown -R root:apache #{@www_yum_dir}/ #{ '&> /dev/null' if @silent }")
47
+ system("chmod -R u=rwX,g=rX,o-rwx #{@www_yum_dir}/")
48
+ raise RuntimeError, "chmod -R u=rwX,g=rX,o-rwx #{@www_yum_dir}/ failed!" unless ($?.nil? || $?.success?)
49
+ say_green "Finished configuring Updates repository at #{yumpath}/Updates" if !@silent
50
+ rescue => err
51
+ say_red "ERROR: Something went wrong setting up the Updates repo in #{yumpath}!"
52
+ say_red ' Please make sure your Updates repo is properly configured.'
53
+ say_red "\nError output:\n #{err.class}\n\n #{err}"
54
+ result = false
55
+ end
56
+
57
+ # disable any CentOS repo spam
58
+ Dir.chdir( @yum_repos_d ) do
59
+ if ! Dir.glob('CentOS*.repo').empty?
60
+ `grep "\\[*\\]" *CentOS*.repo | cut -d "[" -f2 | cut -d "]" -f1 | xargs yum-config-manager --disable`
61
+ end
62
+
63
+ # enable 'simp::yum::enable_simp_repos' in hosts/puppet.your.domain.yaml
64
+ if @config_items.fetch('is_master_yum_server').value && !File.exist?('filesystem.repo')
65
+ cmd = %Q{sed -i '/simp::yum::enable_simp_repos : false/ c\\simp::yum::enable_simp_repos : true' #{@yaml_file}}
66
+ puts cmd if !@silent
67
+ %x{#{cmd}}
68
+ result = result && ($?.nil? || $?.success?)
69
+ end
70
+ end
71
+
72
+ result
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,236 @@
1
+ require File.expand_path( 'item', File.dirname(__FILE__) )
2
+
3
+ module Simp; end
4
+ class Simp::Cli; end
5
+ module Simp::Cli::Config; end
6
+
7
+ # Builds an Array of Config::Items
8
+ class Simp::Cli::Config::ItemListFactory
9
+ def initialize( options )
10
+ @options = {
11
+ :verbose => 0,
12
+ :puppet_system_file => '/tmp/out.yaml',
13
+ }.merge( options )
14
+
15
+ # A hash to look up Config::Item values set from other sources (files, cli).
16
+ # for each Hash element:
17
+ # - the key will be the the Config::Item#key
18
+ # - the value will be the @options#value
19
+ @answers_hash = {}
20
+ end
21
+
22
+
23
+ def process( yaml=nil, answers_hash={} )
24
+ @answers_hash = answers_hash
25
+
26
+ # Require the config items
27
+ rb_files = File.expand_path( '../config/item/*.rb', File.dirname(__FILE__))
28
+ Dir.glob( rb_files ).sort_by(&:to_s).each { |file| require file }
29
+
30
+ items_yaml = yaml || <<-EOF.gsub(/^ {6}/,'')
31
+ # The Config::Item list is really a conditional tree. Some Items can
32
+ # prepend additional Items to the queue, depending on the answer.
33
+ #
34
+ # This YAML describes the full Item structure. The format is:
35
+ #
36
+ # - ItemA
37
+ # - ItemB
38
+ # answer1:
39
+ # - ItemC
40
+ # - ItemD
41
+ # answer2:
42
+ # - ItemE
43
+ # - ItemF
44
+ # - ItemG
45
+ ---
46
+ # ==== network ====
47
+ - UseFips
48
+ - NetworkInterface
49
+ - SetupNIC:
50
+ true:
51
+ - DHCP:
52
+ static: # gather info first, then configure network
53
+ - Hostname
54
+ - IPAddress
55
+ - Netmask
56
+ - Gateway
57
+ - DNSServers
58
+ - DNSSearch
59
+ - NetworkConf
60
+ dhcp: # configure network, then get info (silently)
61
+ - NetworkConf
62
+ - Hostname SILENT
63
+ - IPAddress SILENT
64
+ - Netmask SILENT
65
+ - Gateway SILENT
66
+ - DNSServers SILENT
67
+ - DNSSearch SILENT
68
+ false: # don't configure network (but get network info)
69
+ - Hostname
70
+ - IPAddress
71
+ - Netmask
72
+ - Gateway
73
+ - DNSServers
74
+ - DNSSearch
75
+ - HostnameConf
76
+ - ClientNets
77
+
78
+ # ==== globals ====
79
+ - NTPServers NOAPPLY
80
+ - LogServers
81
+ - FailoverLogServers
82
+ - SimpYumServers
83
+ - UseAuditd
84
+ - UseIPtables
85
+ - CommonRunLevelDefault
86
+ - UseSELinux
87
+ - SetGrubPassword:
88
+ true:
89
+ - GrubPassword
90
+ - Certificates
91
+ - IsMasterYumServer
92
+ - YumRepositories
93
+ - RenameFqdnYaml
94
+
95
+ # ==== puppet ====
96
+ - PuppetServer
97
+ - PuppetServerIP
98
+ - PuppetCA
99
+ - PuppetCAPort
100
+ ### NOTE: removed since update to puppet server: - PuppetFileServer
101
+ - PuppetAutosign
102
+ - PuppetConf
103
+ - PuppetHostsEntry
104
+ - PuppetDBServer
105
+ - PuppetDBPort
106
+
107
+ # ==== ldap ====
108
+ - UseLdap:
109
+ true:
110
+ - AddLdapToHiera
111
+ - LdapBaseDn
112
+ - LdapBindDn
113
+ - LdapBindPw
114
+ - LdapBindHash
115
+ - LdapSyncDn
116
+ - LdapSyncPw
117
+ - LdapSyncHash
118
+ - LdapRootDn
119
+ - LdapRootHash
120
+ - LdapMaster
121
+ - LdapUri
122
+ false:
123
+ - RemoveLdapFromHiera
124
+
125
+ # ==== rsync ====
126
+ - RsyncBase
127
+ - RsyncServer
128
+ - RsyncTimeout
129
+
130
+ # ==== writers ====
131
+ - AnswersYAMLFileWriter FILE=#{ @options.fetch( :puppet_system_file, '/dev/null') }
132
+ - AnswersYAMLFileWriter FILE=#{ @options.fetch( :output_file, '/dev/null') } USERAPPLY
133
+ EOF
134
+ items = YAML.load items_yaml
135
+ item_queue = build_item_queue( [], items )
136
+ item_queue
137
+ end
138
+
139
+
140
+
141
+ def assign_value_from_hash( hash, item )
142
+ value = hash.fetch( item.key, nil )
143
+ if !value.nil?
144
+ # workaround to allow cli/env var arrays
145
+ value = value.split(',,') if item.is_a?(Simp::Cli::Config::ListItem) && !value.is_a?(Array)
146
+ if ! item.validate value
147
+ print_warning "'#{value}' is not an acceptable answer for '#{item.key}' (skipping)."
148
+ else
149
+ item.value = value
150
+ end
151
+ end
152
+ item
153
+ end
154
+
155
+
156
+ # returns an instance of an Config::Item based on a String of its class name
157
+ def create_item item_string
158
+ # create item instance
159
+ parts = item_string.split( /\s+/ )
160
+ name = parts.shift
161
+ item = Simp::Cli::Config::Item.const_get(name).new
162
+
163
+ # set item options
164
+ # ...based on YAML keywords
165
+ while !parts.empty?
166
+ part = parts.shift
167
+ if part =~ /^#/
168
+ parts = []
169
+ next
170
+ end
171
+ item.silent = true if part == 'SILENT'
172
+ item.skip_apply = true if part == 'NOAPPLY'
173
+ item.skip_query = true if part == 'SKIPQUERY'
174
+ item.skip_yaml = true if part == 'NOYAML'
175
+ item.allow_user_apply = true if part == 'USERAPPLY'
176
+ if part =~ /^FILE=(.+)/
177
+ item.file = $1
178
+ end
179
+
180
+ end
181
+ # ...based on cli options
182
+ item.silent = true if @options.fetch( :verbose ) < 0
183
+ item.skip_apply = true if @options.fetch( :dry_run, false )
184
+
185
+ # (try to) assign item values from various sources
186
+ item = assign_value_from_hash( @answers_hash, item )
187
+ end
188
+
189
+
190
+ # recursively build an item queue
191
+ def build_item_queue( item_queue, items )
192
+ writer = create_safety_writer_item
193
+ if !items.empty?
194
+ item = items.shift
195
+ item_queue << writer if writer
196
+
197
+ if item.is_a? String
198
+ item_queue << create_item( item )
199
+
200
+ elsif item.is_a? Hash
201
+ answers_tree = {}
202
+ item.values.first.each{ |answer, values|
203
+ answers_tree[ answer ] = build_item_queue( [], values )
204
+ }
205
+ _item = create_item( item.keys.first )
206
+ _item.next_items_tree = answers_tree
207
+ item_queue << _item
208
+ item_queue << writer if writer
209
+ end
210
+
211
+ item_queue = build_item_queue( item_queue, items )
212
+ end
213
+
214
+ # append a silent YAML writer to save progress after each item
215
+
216
+ item_queue
217
+ end
218
+
219
+
220
+ # create a YAML writer that will "safety save" after each answer
221
+ def create_safety_writer_item
222
+ if file = @options.fetch( :output_file, nil)
223
+ FileUtils.mkdir_p File.dirname( file ), :verbose => false
224
+ writer = Simp::Cli::Config::Item::AnswersYAMLFileWriter.new
225
+ file = File.join( File.dirname( file ), ".#{File.basename( file )}" )
226
+ writer.file = file
227
+ writer.allow_user_apply = true
228
+ writer.silent = true if @options.fetch(:verbose, 0) < 2
229
+ writer
230
+ end
231
+ end
232
+
233
+ def print_warning error
234
+ say "<%= color(%q{WARNING: }, YELLOW,BOLD) %><%= color(%q{#{error}}, YELLOW) %>\n"
235
+ end
236
+ end