-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add smart_proxy_chef plugin support #152
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# = Foreman Proxy Chef plugin | ||
# | ||
# This class installs chef plugin | ||
# | ||
# === Parameters: | ||
# | ||
# $group:: group owner of the configuration file | ||
# | ||
# $version:: plugin package version, it's passed to ensure parameter of package resource | ||
# can be set to specific version number, 'latest', 'present' etc. | ||
# | ||
# $enabled:: enables/disables the plugin | ||
# | ||
# $listen_on:: Proxy feature listens on http, https, or both | ||
# | ||
# $server_url:: chef server url | ||
# | ||
# $client_name:: chef client name used for authentication of other client requests | ||
# | ||
# $private_key:: path to file containing private key for $client_name client | ||
# | ||
# $ssl_verify:: should we perform chef server ssl cert verification? this requires | ||
# CA certificate installed and trusted | ||
# type:boolean | ||
# | ||
# $ssl_pem_file:: if $ssl_verify is true you can specify a path to a file which | ||
# contains certificate and related private key if the certificate | ||
# is not globally trusted | ||
# | ||
class foreman_proxy::plugin::chef ( | ||
$enabled = $::foreman_proxy::plugin::chef::params::enabled, | ||
$listen_on = $::foreman_proxy::plugin::chef::params::listen_on, | ||
$version = $::foreman_proxy::plugin::chef::params::version, | ||
$group = $::foreman_proxy::plugin::chef::params::group, | ||
$server_url = $::foreman_proxy::plugin::chef::params::server_url, | ||
$client_name = $::foreman_proxy::plugin::chef::params::client_name, | ||
$private_key = $::foreman_proxy::plugin::chef::params::private_key, | ||
$ssl_verify = $::foreman_proxy::plugin::chef::params::ssl_verify, | ||
$ssl_pem_file = $::foreman_proxy::plugin::chef::params::ssl_pem_file, | ||
) inherits foreman_proxy::plugin::chef::params { | ||
|
||
validate_bool($enabled) | ||
validate_listen_on($listen_on) | ||
|
||
foreman_proxy::plugin {'chef': | ||
version => $version, | ||
} -> | ||
foreman_proxy::settings_file { 'chef': | ||
listen_on => $listen_on, | ||
enabled => $enabled, | ||
group => $group, | ||
template_path => 'foreman_proxy/plugin/chef.yml.erb', | ||
} | ||
} |
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 @@ | ||
# Default parameters for the Chef smart proxy plugin | ||
class foreman_proxy::plugin::chef::params { | ||
$enabled = true | ||
$group = undef | ||
$listen_on = 'https' | ||
$version = undef | ||
$server_url = "https://${::fqdn}" | ||
$client_name = $::fqdn | ||
$private_key = '/etc/chef/client.pem' | ||
$ssl_verify = true | ||
$ssl_pem_file = undef | ||
} |
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,41 @@ | ||
require 'spec_helper' | ||
|
||
describe 'foreman_proxy::plugin::chef' do | ||
on_supported_os.each do |os, facts| | ||
context "on #{os}" do | ||
context 'chef plugin is enabled' do | ||
let :params do | ||
{ | ||
:enabled => true | ||
} | ||
end | ||
|
||
it 'should call the plugin' do | ||
should contain_foreman_proxy__plugin('chef') | ||
end | ||
|
||
it 'should install configuration file' do | ||
should contain_foreman_proxy__settings_file('chef') | ||
should contain_file('/etc/foreman-proxy/settings.d/chef.yml').with_content(/:enabled: true/) | ||
end | ||
end | ||
|
||
context 'chef plugin is disabled' do | ||
let :params do | ||
{ | ||
:enabled => false | ||
} | ||
end | ||
|
||
it 'should call the plugin' do | ||
should contain_foreman_proxy__plugin('chef') | ||
end | ||
|
||
it 'should install configuration file' do | ||
should contain_foreman_proxy__settings_file('chef') | ||
should contain_file('/etc/foreman-proxy/settings.d/chef.yml').with_content(/:enabled: false/) | ||
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,4 +1,8 @@ | ||
def verify_exact_contents(subject, title, expected_lines) | ||
get_content(subject, title).should == expected_lines | ||
end | ||
|
||
def get_content(subject, title) | ||
content = subject.resource('file', title).send(:parameters)[:content] | ||
content.split(/\n/).reject { |line| line =~ /(^#|^$|^\s+#)/ }.should == expected_lines | ||
content.split(/\n/).reject { |line| line =~ /(^#|^$|^\s+#)/ } | ||
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
:enabled: <%= scope.lookupvar("foreman_proxy::plugin::chef::enabled") %> | ||
:chef_authenticate_nodes: true | ||
:chef_server_url: <%= scope.lookupvar("foreman_proxy::plugin::chef::server_url") %> | ||
# smart-proxy client node needs to have some admin right on chef-server | ||
# in order to retrive all nodes public keys | ||
# e.g. 'host.example.net' | ||
:chef_smartproxy_clientname: <%= scope.lookupvar("foreman_proxy::plugin::chef::client_name") %> | ||
# e.g. /etc/chef/client.pem | ||
:chef_smartproxy_privatekey: <%= scope.lookupvar("foreman_proxy::plugin::chef::private_key") %> | ||
|
||
# turning of chef_ssl_verify is not recommended as it turn off authentication | ||
# you can try set path to chef server certificate by chef_ssl_pem_file | ||
# before setting chef_ssl_verify to false | ||
# note that chef_ssl_pem_file must contain both private key and certificate | ||
# because chef-api 0.5 requires it | ||
:chef_ssl_verify: <%= scope.lookupvar("foreman_proxy::plugin::chef::ssl_verify") %> | ||
<% custom_pem = scope.lookupvar("foreman_proxy::plugin::chef::ssl_pem_file") -%> | ||
<% if !custom_pem.nil? && !['', :undef, :undefined].include?(custom_pem)-%> | ||
:chef_ssl_pem_file: <%= custom_pem %> | ||
<% else -%> | ||
# :chef_ssl_pem_file: /path | ||
<% end -%> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loads
templates/chef.yml.erb
while the file is calledtemplates/plugin/chef.yml.erb
which leads to red tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most plugins override it with
template_path
so I think that would be best here as well.