Revision 2e2065d0
Added by Dominic Cleal almost 10 years ago
manifests/cli.pp | ||
---|---|---|
# = Foreman command line interface
|
||
#
|
||
# This class installs the Hammer command line interface (CLI).
|
||
#
|
||
# $foreman_url:: URL on which Foreman runs
|
||
#
|
||
# $username:: Username for authentication
|
||
#
|
||
# $password:: Password for authentication
|
||
#
|
||
# === Advanced parameters:
|
||
#
|
||
# $manage_root_config:: Whether to manage /root/.hammer configuration.
|
||
# type:boolean
|
||
#
|
||
# $refresh_cache:: Check API documentation cache status on each request
|
||
# type:boolean
|
||
#
|
||
# $request_timeout:: API request timeout, set -1 for infinity
|
||
# type:integer
|
||
#
|
||
class foreman::cli (
|
||
$foreman_url = $::foreman::cli::params::foreman_url,
|
||
$manage_root_config = $::foreman::cli::params::manage_root_config,
|
||
$username = $::foreman::cli::params::username,
|
||
$password = $::foreman::cli::params::password,
|
||
$refresh_cache = $::foreman::cli::params::refresh_cache,
|
||
$request_timeout = $::foreman::cli::params::request_timeout,
|
||
) inherits foreman::cli::params {
|
||
# Inherit URL & auth parameters from foreman class if possible
|
||
$foreman_url_real = pick($foreman_url, $::foreman::foreman_url)
|
||
validate_string($foreman_url_real, $username, $password)
|
||
validate_bool($manage_root_config, $refresh_cache)
|
||
|
||
package { 'foreman-cli':
|
||
ensure => installed,
|
||
} ->
|
||
file { '/etc/hammer/cli.modules.d/foreman.yml':
|
||
ensure => present,
|
||
owner => 'root',
|
||
group => 'root',
|
||
mode => '0644',
|
||
content => template('foreman/hammer_etc.yml.erb'),
|
||
}
|
||
|
||
# Separate configuration for admin username/password
|
||
if $manage_root_config {
|
||
file { '/root/.hammer':
|
||
ensure => directory,
|
||
owner => 'root',
|
||
group => 'root',
|
||
mode => '0600',
|
||
}
|
||
file { '/root/.hammer/cli.modules.d':
|
||
ensure => directory,
|
||
owner => 'root',
|
||
group => 'root',
|
||
mode => '0600',
|
||
}
|
||
file { '/root/.hammer/cli.modules.d/foreman.yml':
|
||
ensure => present,
|
||
owner => 'root',
|
||
group => 'root',
|
||
mode => '0600',
|
||
replace => false,
|
||
content => template('foreman/hammer_root.yml.erb'),
|
||
}
|
||
}
|
||
}
|
manifests/cli/params.pp | ||
---|---|---|
# Parameters for Foreman CLI class
|
||
class foreman::cli::params {
|
||
$foreman_url = undef
|
||
$manage_root_config = true
|
||
$username = 'admin'
|
||
$password = 'changeme'
|
||
$refresh_cache = false
|
||
$request_timeout = 120
|
||
}
|
spec/classes/foreman_cli_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'foreman::cli' do
|
||
context 'standalone with parameters' do
|
||
let(:params) do {
|
||
'foreman_url' => 'http://example.com',
|
||
} end
|
||
|
||
it { should contain_package('foreman-cli').with_ensure('installed') }
|
||
|
||
describe '/etc/hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings' do
|
||
content = subject.resource('file', '/etc/hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :enable_module: true",
|
||
" :host: 'http://example.com'",
|
||
]
|
||
end
|
||
end
|
||
|
||
describe '/root/.hammer/cli.modules.d/foreman.yml' do
|
||
it { should contain_file('/root/.hammer/cli.modules.d/foreman.yml').with_replace(false) }
|
||
|
||
it 'should contain settings' do
|
||
content = subject.resource('file', '/root/.hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :username: 'admin'",
|
||
" :password: 'changeme'",
|
||
" :refresh_cache: false",
|
||
" :request_timeout: 120",
|
||
]
|
||
end
|
||
end
|
||
|
||
describe 'with manage_root_config=false' do
|
||
let(:params) do {
|
||
'foreman_url' => 'http://example.com',
|
||
'manage_root_config' => false,
|
||
} end
|
||
|
||
it { should_not contain_file('/root/.hammer') }
|
||
it { should_not contain_file('/root/.hammer/cli.modules.d/foreman.yml') }
|
||
end
|
||
end
|
||
|
||
context 'with foreman' do
|
||
let :facts do {
|
||
:concat_basedir => '/tmp',
|
||
:operatingsystemrelease => '6.4',
|
||
:operatingsystem=> 'RedHat',
|
||
:osfamily => 'RedHat',
|
||
:fqdn => 'foreman.example.com',
|
||
} end
|
||
|
||
let :pre_condition do
|
||
"class { 'foreman': }"
|
||
end
|
||
|
||
it { should contain_package('foreman-cli').with_ensure('installed') }
|
||
|
||
describe '/etc/hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings from foreman' do
|
||
content = subject.resource('file', '/etc/hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :enable_module: true",
|
||
" :host: 'https://#{facts[:fqdn]}'",
|
||
]
|
||
end
|
||
end
|
||
end
|
||
end
|
templates/hammer_etc.yml.erb | ||
---|---|---|
:foreman:
|
||
# Enable/disable foreman commands
|
||
:enable_module: true
|
||
|
||
# Your foreman server address
|
||
:host: '<%= @foreman_url_real %>'
|
templates/hammer_root.yml.erb | ||
---|---|---|
:foreman:
|
||
# Credentials. You'll be asked for the interactively if you leave them blank here
|
||
:username: '<%= @username %>'
|
||
:password: '<%= @password %>'
|
||
|
||
# Check API documentation cache status on each request
|
||
:refresh_cache: <%= @refresh_cache %>
|
||
|
||
# API request timeout in seconds, set -1 for infinity
|
||
:request_timeout: <%= @request_timeout %>
|
Also available in: Unified diff
Add foreman::cli class to install Hammer