Module: Beaker::DSL::InstallUtils::PuppetUtils
- Included in:
- FOSSUtils, BeakerPuppet
- Defined in:
- lib/beaker-puppet/install_utils/puppet_utils.rb
Overview
This module contains methods useful for both foss and pe installs
Instance Method Summary collapse
-
#add_puppet_paths_on(hosts) ⇒ Object
Append puppetbindir, facterbindir and hierabindir to the PATH for each host.
-
#configure_defaults_on(hosts, type) ⇒ Object
Configure the provided hosts to be of the provided type (one of foss, aio, pe), if the host is already associated with a type then remove the previous settings for that type.
- #configure_type_defaults_on(hosts) ⇒ Object (also: #configure_foss_defaults_on, #configure_pe_defaults_on)
-
#construct_puppet_path(host) ⇒ Object
Given a host construct a PATH that includes puppetbindir, facterbindir and hierabindir.
-
#normalize_type(type) ⇒ String
Given a type return an understood host type.
-
#puppet_agent_version_on(host) ⇒ Object
Report the version of puppet-agent installed on ‘host`.
-
#puppet_collection_for(package, version) ⇒ Object
Determine the puppet collection that matches a given package version.
-
#puppetserver_version_on(host) ⇒ Object
Report the version of puppetserver installed on ‘host`.
-
#remove_defaults_on(hosts) ⇒ Object
If the host is associated with a type remove all defaults and environment associated with that type.
-
#remove_puppet_paths_on(hosts) ⇒ Object
Remove puppetbindir, facterbindir and hierabindir to the PATH for each host.
-
#stop_firewall_with_puppet_on(hosts) ⇒ Object
Uses puppet to stop the firewall on the given hosts.
Instance Method Details
#add_puppet_paths_on(hosts) ⇒ Object
Append puppetbindir, facterbindir and hierabindir to the PATH for each host
50 51 52 53 54 55 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 50 def add_puppet_paths_on(hosts) block_on hosts do |host| puppet_path = construct_puppet_path(host) host.add_env_var('PATH', puppet_path) end end |
#configure_defaults_on(hosts, type) ⇒ Object
Configure the provided hosts to be of the provided type (one of foss, aio, pe), if the host is already associated with a type then remove the previous settings for that type
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 138 def configure_defaults_on(hosts, type) block_on hosts do |host| # check to see if the host already has a type associated with it remove_defaults_on(host) add_method = "add_#{type}_defaults_on" raise "cannot add defaults of type #{type} for host #{host.name} (#{add_method} not present)" unless respond_to?( add_method, host ) send(add_method, host) # add pathing env add_puppet_paths_on(host) end end |
#configure_type_defaults_on(hosts) ⇒ Object Also known as: configure_foss_defaults_on, configure_pe_defaults_on
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 156 def configure_type_defaults_on(hosts) block_on hosts do |host| has_defaults = false if host[:type] host_type = host[:type] # clean up the naming conventions here (some teams use foss-package, git-whatever, we need # to correctly handle that # don't worry about aio, that happens in the aio_version? check host_type = normalize_type(host_type) if host_type and host_type !~ /aio/ add_method = "add_#{host_type}_defaults_on" raise "cannot add defaults of type #{host_type} for host #{host.name} (#{add_method} not present)" unless respond_to?( add_method, host ) send(add_method, host) has_defaults = true end end if aio_version?(host) add_aio_defaults_on(host) has_defaults = true end # add pathing env add_puppet_paths_on(host) if has_defaults end end |
#construct_puppet_path(host) ⇒ Object
Given a host construct a PATH that includes puppetbindir, facterbindir and hierabindir
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 34 def construct_puppet_path(host) path = %w[puppetbindir facterbindir hierabindir privatebindir].compact.reject(&:empty?) # get the PATH defaults path.map! { |val| host[val] } path = path.compact.reject(&:empty?) # run the paths through echo to see if they have any subcommands that need processing path.map! { |val| echo_on(host, val) } separator = host['pathseparator'] separator = ':' unless host.is_powershell? path.join(separator) end |
#normalize_type(type) ⇒ String
Given a type return an understood host type
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 21 def normalize_type(type) case type when /(\A|-)foss(\Z|-)/ 'foss' when /(\A|-)pe(\Z|-)/ 'pe' when /(\A|-)aio(\Z|-)/ 'aio' end end |
#puppet_agent_version_on(host) ⇒ Object
Report the version of puppet-agent installed on ‘host`
113 114 115 116 117 118 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 113 def puppet_agent_version_on(host) result = on(host, facter('aio_agent_version'), accept_all_exit_codes: true) return result.stdout.strip if result.exit_code.zero? nil end |
#puppet_collection_for(package, version) ⇒ Object
Determine the puppet collection that matches a given package version. The package must be one of
* :puppet_agent (you can get this version from the `aio_agent_version_fact`)
* :puppet
* :puppetserver
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 78 def puppet_collection_for(package, version) valid_packages = %i[ puppet_agent puppet puppetserver ] raise "package must be one of #{valid_packages.join(', ')}" unless valid_packages.include?(package) case package when :puppet_agent, :puppet, :puppetserver version = version.to_s return 'puppet' if version.strip == 'latest' x, y, z = version.to_s.split('.').map(&:to_i) return nil if x.nil? || y.nil? || z.nil? pc1_x = { puppet: 4, puppet_agent: 1, puppetserver: 2, } return 'pc1' if x == pc1_x[package] # A y version >= 99 indicates a pre-release version of the next x release x += 1 if y >= 99 "puppet#{x}" if x > 4 end end |
#puppetserver_version_on(host) ⇒ Object
Report the version of puppetserver installed on ‘host`
124 125 126 127 128 129 130 131 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 124 def puppetserver_version_on(host) result = on(host, 'puppetserver --version', accept_all_exit_codes: true) if result.exit_code.zero? matched = result.stdout.strip.scan(/\d+\.\d+\.\d+/) return matched.first end nil end |
#remove_defaults_on(hosts) ⇒ Object
If the host is associated with a type remove all defaults and environment associated with that type.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 190 def remove_defaults_on(hosts) block_on hosts do |host| if host['type'] # clean up the naming conventions here (some teams use foss-package, git-whatever, we need # to correctly handle that # don't worry about aio, that happens in the aio_version? check host_type = normalize_type(host['type']) remove_puppet_paths_on(hosts) remove_method = "remove_#{host_type}_defaults_on" raise "cannot remove defaults of type #{host_type} associated with host #{host.name} (#{remove_method} not present)" unless respond_to?( remove_method, host ) send(remove_method, host) remove_aio_defaults_on(host) if aio_version?(host) end end end |
#remove_puppet_paths_on(hosts) ⇒ Object
Remove puppetbindir, facterbindir and hierabindir to the PATH for each host
61 62 63 64 65 66 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 61 def remove_puppet_paths_on(hosts) block_on hosts do |host| puppet_path = construct_puppet_path(host) host.delete_env_var('PATH', puppet_path) end end |
#stop_firewall_with_puppet_on(hosts) ⇒ Object
Uses puppet to stop the firewall on the given hosts. Puppet must be installed before calling this method.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/beaker-puppet/install_utils/puppet_utils.rb', line 212 def stop_firewall_with_puppet_on(hosts) block_on hosts do |host| case host['platform'] when /debian/ result = on(host, 'which iptables', accept_all_exit_codes: true) if result.exit_code == 0 on host, 'iptables -F' else logger.notify("Unable to locate `iptables` on #{host['platform']}; not attempting to clear firewall") end when /fedora|el-7/ on host, puppet('resource', 'service', 'firewalld', 'ensure=stopped') when /el-|centos/ on host, puppet('resource', 'service', 'iptables', 'ensure=stopped') when /ubuntu/ on host, puppet('resource', 'service', 'ufw', 'ensure=stopped') else logger.notify("Not sure how to clear firewall on #{host['platform']}") end end end |