-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #13667 - support for puppet 4.0 in puppet_proxy module
- Loading branch information
Showing
111 changed files
with
2,190 additions
and
1,339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
group :puppet, :puppetca do | ||
group :puppet_proxy_legacy do | ||
gem 'puppet', '< 5.0.0' | ||
gem 'ruby-augeas', :require => 'augeas' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
# Set :command to the full path of the script you want to run, instead of /bin/false | ||
#:command: /bin/false | ||
# | ||
# Set :command_arguments to any args you want to pass to your custom script. The hostname of the | ||
# system to run against will be appended after the custom commands. | ||
#:command_arguments: -ay -f -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# puppet_proxy_legacy module is used for puppet versions prior to 4.0 | ||
# | ||
# puppet_proxy_legacy is configured automatcially based on | ||
# :puppet_version setting in smart-proxy's puppet.yml configuration file. | ||
# | ||
--- | ||
#:puppet_conf: /etc/puppet/puppet.conf | ||
# | ||
# Override use of Puppet's API to list environments, by default it will use only if | ||
# environmentpath is given in puppet.conf, else will look for environments in puppet.conf | ||
# (Puppet versions prior to 4.0 only) | ||
#:use_environment_api: true | ||
# | ||
# URL of the puppet master itself for API requests. Required if puppet_use_environment_api is set to true. | ||
#:puppet_url: https://puppet.example.com:8140 | ||
# | ||
# SSL certificates used to access the environment API. Required if puppet_use_environment_api is set to true. | ||
#:puppet_ssl_ca: /var/lib/puppet/ssl/certs/ca.pem | ||
#:puppet_ssl_cert: /var/lib/puppet/ssl/certs/puppet.example.com.pem | ||
#:puppet_ssl_key: /var/lib/puppet/ssl/private_keys/puppet.example.com.pem | ||
# | ||
# Enable/disable puppet class cache | ||
#:use_cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
# | ||
# User for execution of mco commands | ||
# | ||
# sudo permission needs to be added to ensure | ||
# smart-proxy can execute 'sudo' command | ||
# | ||
# For Puppet Enterprise this means | ||
# Defaults:foreman-proxy !requiretty | ||
# foreman-proxy ALL=(peadmin) NOPASSWD: /opt/puppet/bin/mco *', | ||
# | ||
#:user: peadmin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# puppet_proxy_pupppet_api module is used for puppet versions 4.0 and higher | ||
# | ||
# puppet_proxy_pupppet_api is configured automatcially based on | ||
# :puppet_version setting in smart-proxy's puppet.yml configuration file. | ||
# | ||
--- | ||
# URL of the puppet master itself for API requests. | ||
#:puppet_url: https://puppet.example.com:8140 | ||
# | ||
# SSL certificates used to access the puppet API | ||
#:puppet_ssl_ca: /var/lib/puppet/ssl/certs/ca.pem | ||
#:puppet_ssl_cert: /var/lib/puppet/ssl/certs/puppet.example.com.pem | ||
#:puppet_ssl_key: /var/lib/puppet/ssl/private_keys/puppet.example.com.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
# | ||
# User for execution of puppetrun commands | ||
# | ||
# sudo permission needs to be added to ensure | ||
# smart-proxy can execute 'sudo' command | ||
# | ||
# Defaults:foreman-proxy !requiretty | ||
# foreman-proxy ALL=(peadmin) NOPASSWD: /opt/puppet/bin/puppet *', | ||
# | ||
# or | ||
# | ||
# Defaults:foreman-proxy !requiretty | ||
# foreman-proxy ALL=(peadmin) NOPASSWD: /opt/puppet/bin/puppetrun *', | ||
# | ||
#:user: peadmin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# Set :command to 'puppet.run agent no-noop' to run in no-noop mode. Default command is puppet.run. | ||
#:command: puppet.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
# the command which will be sent to the host | ||
#:command: puppet agent --onetime --no-usecacheonfailure | ||
# | ||
# whether to use sudo before the ssh command | ||
#:use_sudo: false | ||
# | ||
# wait for the command to finish (and capture exit code), or detach process and return 0 | ||
# Note: enabling this option causes the Foreman web UI to be blocked when executing puppetrun, | ||
# with timeout from the Browser and/or Foreman's REST client after 60 seconds. | ||
#:wait: false | ||
# | ||
# With which user should the proxy connect | ||
#:user: root | ||
#:keyfile: /etc/foreman-proxy/id_rsa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
extra/migrations/20160413000000_migrate_puppet_settings.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
require 'yaml' | ||
|
||
class MigratePuppetSettings < ::Proxy::Migration | ||
KNOWN_PARAMETERS = { | ||
:enabled => [:puppet, :enabled], | ||
:puppet_provider => [:puppet, :use_provider], | ||
:puppet_user => [:puppet_proxy_puppetrun, :puppet_proxy_mcollective, :puppet_user], | ||
:salt_puppetrun_cmd => [:puppet_proxy_salt, :command], | ||
:customrun_cmd => [:puppet_proxy_customrun, :command], | ||
:customrun_args => [:puppet_proxy_customrun, :command_arguments], | ||
:use_cache => [:puppet_proxy_legacy, :use_cache], | ||
:puppet_conf => [:puppet_proxy_legacy, :puppet_conf], | ||
:puppet_use_environment_api => [:puppet_proxy_legacy, :use_environment_api], | ||
:puppet_url => [:puppet_proxy_legacy, :puppet_proxy_puppet_api, :puppet_url], | ||
:puppet_ssl_ca => [:puppet_proxy_legacy, :puppet_proxy_puppet_api, :puppet_ssl_ca], | ||
:puppet_ssl_cert => [:puppet_proxy_legacy, :puppet_proxy_puppet_api, :puppet_ssl_cert], | ||
:puppet_ssl_key => [:puppet_proxy_legacy, :puppet_proxy_puppet_api, :puppet_ssl_key], | ||
:puppetssh_sudo => [:puppet_proxy_ssh, :use_sudo], | ||
:puppetssh_command => [:puppet_proxy_ssh, :command], | ||
:puppetssh_wait => [:puppet_proxy_ssh, :wait], | ||
:puppetssh_user => [:puppet_proxy_ssh, :user], | ||
:puppetssh_keyfile => [:puppet_proxy_ssh, :keyfile], | ||
:mcollective_user => [:puppet_proxy_mcollective, :user] | ||
} | ||
|
||
def migrate | ||
puppet_config = path(src_dir, "settings.d", "puppet.yml") | ||
if !File.exist?(puppet_config) | ||
duplicate_original_configuration | ||
return | ||
end | ||
|
||
to_migrate = YAML.load_file(puppet_config) | ||
|
||
output = migrate_puppet_configuration(to_migrate) | ||
copy_original_configuration_except(path("settings.d", "puppet.yml")) | ||
write_to_files(output) | ||
end | ||
|
||
def remap_parameter(aparameter, avalue) | ||
module_names_to_parameter = KNOWN_PARAMETERS.has_key?(aparameter) ? KNOWN_PARAMETERS[aparameter] : [:unknown, aparameter] | ||
parameter_name = module_names_to_parameter.last | ||
module_names = module_names_to_parameter[0..-2] | ||
|
||
avalue = old_provider_name_to_new(avalue) if parameter_name == :use_provider | ||
module_names.map {|module_name| [module_name, parameter_name, avalue]} | ||
end | ||
|
||
def old_provider_name_to_new(aname) | ||
if ['puppetrun', 'mcollective', 'puppetssh', 'salt', 'customrun'].include?(aname) | ||
aname == 'puppetssh' ? 'puppet_proxy_ssh' : 'puppet_proxy_' + aname | ||
else | ||
aname | ||
end | ||
end | ||
|
||
def puppet_version | ||
require 'puppet' | ||
Puppet::PUPPETVERSION | ||
rescue Exception | ||
"4.3.1" | ||
end | ||
|
||
def migrate_puppet_configuration(to_migrate) | ||
migrated = Hash.new { |h,k| h[k] = Hash.new } | ||
to_migrate.each do |option, value| | ||
remap_parameter(option, value).each {|module_name, parameter_name, parameter_value| migrated[module_name][parameter_name] = parameter_value} | ||
end | ||
|
||
# deal with puppet_user setting, which used to be global, but has been moved (and renamed) to puppetrun and mcollective modules | ||
if migrated.has_key?(:puppet_proxy_puppetrun) | ||
puppetrun_user = migrated[:puppet_proxy_puppetrun].delete(:puppet_user) | ||
migrated[:puppet_proxy_puppetrun][:user] = puppetrun_user unless puppetrun_user.nil? | ||
end | ||
|
||
if migrated.has_key?(:puppet_proxy_mcollective) | ||
puppet_user = migrated[:puppet_proxy_mcollective].delete(:puppet_user) | ||
if !(migrated[:puppet_proxy_mcollective].has_key?(:user) || puppet_user.nil?) | ||
migrated[:puppet_proxy_mcollective][:user] = puppet_user | ||
end | ||
end | ||
|
||
migrated[:puppet][:puppet_version] = puppet_version | ||
|
||
migrated | ||
end | ||
|
||
def write_to_files(output) | ||
output.keys.each do |m| | ||
next if output[m].empty? || m == :unknown | ||
File.open(path(dst_dir, "settings.d", "#{m}.yml"),'w') do |f| | ||
f.write(strip_ruby_symbol_encoding(output[m].to_yaml)) | ||
if (m == :puppet) && !output[:unknown].empty? | ||
f.write "\n# Unparsed options, please review\n" | ||
f.write(strip_ruby_symbol_encoding(output[:unknown].to_yaml).gsub(/^---/,'')) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
module Proxy::Error | ||
class HttpError < StandardError | ||
attr_reader :status_code, :response_body | ||
def initialize(status_code, response_body, msg = nil) | ||
@status_code = status_code | ||
@response_body = response_body | ||
@msg = msg | ||
end | ||
|
||
def to_s | ||
@msg.nil? ? "#{status_code} #{response_body}" : "#{@msg}: #{status_code} #{response_body}" | ||
end | ||
end | ||
|
||
class ConfigurationError < StandardError; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.