I have an ssl cert file that I want to convert into a string before uploading using puppet. Below is what I have:
class ssl_cert {
$cert='domain.com.crt';
$key='domain.com.key';
file { $urlcert :
ensure => present,
}
file { $key :
ensure => present,
}
exec { 'Use $cert':
path => '/opt/',
require => File[$cert],
command => "/bin/sed -E ':a;N;$!ba;s/\r*\n/\\n/g' $cert",
}
exec { 'Use $key':
path => '/opt/',
require => File[$key],
command => "/bin/sed -E ':a;N;$!ba;s/\r*\n/\\n/g' $key",
}
#Upload ssl cert for vhost
brocadevtm::ssl_server_keys { 'domain.com' :
ensure => present,
basic__note => '',
basic__private => $cert,
basic__public => $key,
}
}
Is there a way to pass the exec command (command => "/bin/sed -E ':a;N;$!ba;s/\r*\n/\n/g' $cert",) to a variable which can be called later and used for the values basic__private => ' ' and basic__public => ' '? as it is now, those values are just picking up domain.com.crt and domain.com.key from the variables above but I want to use the output of the command instead and not the file.
Related
I have this simple puppet manifest
class javaora(include ::archive) {
group { 'serviceusrgroup':
name => 'serviceusrgroup',
ensure => 'present',
}
user { 'jersey':
name => 'jersey',
home => '/home/jersey',
gid => 'serviceusrgroup',
comment => 'User to Run servers',
}
file { ['/usrdata/archive', '/usrdata/apps/java']: ensure => 'directory' }
archive { "/usrdata/archive/${tomcat::jreversion}":
ensure => present,
extract => true,
extract_path => '/usrdata/apps/java',
source => $tomcat::jredownload,
creates => "/usrdata/apps/java/${tomcat::jdkversion}"
}
I am getting error Failed to fetch ec2 uri http://169.254.169.254/latest/meta-data/:403 Forbidden
It also gives me error at line 2 : Syntax error near include ; expected ")"
In a cookbook I have the following in my attributes/default.rb:
default.ark.packages = [
{
'name' => 'optipng',
'url' => 'http://squirrelyjim.cloudfront.net/heroes/optipng-0.7.5.tar.gz',
'version' => '0.7.5'
},
{
'name' => 'imagemagick',
'url' => 'http://squirrelyjim.cloudfront.net/heroes/ImageMagick-6.9.0-4.tar.gz',
'version' => '6.9.0-4'
},
{
'name' => 'jpegoptim',
'url' => 'http://squirrelyjim.cloudfront.net/heroes/jpegoptim-1.4.1.tar.gz',
'version' => '1.4.1'
}
]
I then call those values using the ark resource as follows:
node.ark.packages.each do |pkg|
ark pkg['name'] do
url pkg['url']
version pkg['version']
action :install_with_make
notifies :run, "execute[ldconfig]", :immediately
end
end
This works great but I would like to somehow get the version to automatically get called at the end of the url, instead of typing it out twice. Is there a way to get a value in a hash updated with another value from the same hash, similar to:
http://squirrelyjim.cloudfront.net/heroes/optipng-#{version}.tar.gz
Dynamically build the URL inside the loop:
node.ark.packages.each do |pkg|
url = "http://squirrelyjim.cloudfront.net/heroes/#{pkg['name']}-#{pkg['version']}.tar.gz"
ark pkg['name'] do
url url
version pkg['version']
action :install_with_make
notifies :run, "execute[ldconfig]", :immediately
end
end
I am looking for a dry version of the following:
Ideally it could be just an array and a loop. What is the way to go in Puppet?
class hive_cdh4::configs inherits hive_cdh4 {
define hive_configs () {
file { "/etc/hive/conf.rr/hive-site.xml":
owner => root,
group => root,
mode => 664,
ensure => present,
content => template("hive_cdh4/hive-site.xml.erb")
}
file { "/etc/hive/conf.rr/hive-exec-log4j.properties":
owner => root,
group => root,
mode => 664,
ensure => present,
content => template("hive_cdh4/hive-exec-log4j.properties.erb")
}
file { "/etc/hive/conf.rr/hive-log4j.properties":
owner => root,
group => root,
mode => 664,
ensure => present,
content => template("hive_cdh4/hive-log4j.properties.erb")
}
}
}
How about something like this:
define hive_config ($file_name = $title, $format = 'properties') {
file { "/etc/hive/conf.rr/$file_name.$format":
owner => root,
group => root,
mode => '0664',
ensure => present,
content => template("hive_cdh4/$file_name.$format.erb")
}
}
hive_config {'hive-site':}
hive_config {'hive-exec-log4j':}
hive_config {'hive-log4j':
format => 'xml'
}
I tested it quickly in a Vagrant provision, and it seems to work?
I would like to install apache maven by using puppet recipe, but I can not find anywhere an example on how to do this. Can someone help with this? Apache maven is packed as tar.gz file. I am using a stand-alone setup for puppet.
I use this snippet from example42:
define netinstall (
$url,
$extracted_dir,
$destination_dir,
$owner = "root",
$group = "root",
$work_dir = "/var/tmp",
$extract_command = "tar -zxvf",
$preextract_command = "",
$postextract_command = ""
) {
$source_filename = urlfilename($url)
if $preextract_command {
exec {
"PreExtract $source_filename":
command => $preextract_command,
before => Exec["Extract $source_filename"],
refreshonly => true,
}
}
exec {
"Retrieve $url":
cwd => "$work_dir",
command => "wget $url",
creates => "$work_dir/$source_filename",
timeout => 3600,
}
exec {
"Extract $source_filename":
command => "mkdir -p $destination_dir && cd $destination_dir && $extract_command $work_dir/$source_filename",
unless => "find $destination_dir | grep $extracted_dir",
creates => "${destination_dir}/${extracted_dir}",
require => Exec["Retrieve $url"],
}
if $postextract_command {
exec {
"PostExtract $source_filename":
command => $postextract_command,
cwd => "$destination_dir/$extracted_dir",
subscribe => Exec["Extract $source_filename"],
refreshonly => true,
timeout => 3600,
require => Exec["Retrieve $url"],
}
}
}
example usage:
#Install prerequisites
exec { "VPSMonPrerequisites":
command => "yum install -y ${vpsmonitor::params::prerequisites}",
unless => "rpm -qi ${vpsmonitor::params::prerequisites}",
timeout => 3600,
}
#Install tgz from source url
netinstall { vpsmonitor:
url => "${vpsmonitor::params::source_url}",
extracted_dir => "${vpsmonitor::params::extracted_dir}",
destination_dir => "${vpsmonitor::params::destination_dir}",
postextract_command => "chown -R user. ${vpsmonitor::params::destination_dir}/${vpsmonitor::params::extracted_dir}",
require => [ Exec["VPSMonPrerequisites"], User["user"] ],
}
There is a Puppet module that does this job for you: dsestero/download_uncompress
Example:
$phpstorm_version = '2017.2.1'
download_uncompress { 'PhpStorm':
download_base_url => 'https://download.jetbrains.com/webide',
distribution_name => "PhpStorm-${phpstorm_version}.tar.gz",
dest_folder => '/opt',
creates => "/opt/phpstorm-${phpstorm_version}",
uncompress => 'tar.gz',
}
Can I somehow use this
settings = {
'user1' => { 'path' => '/','days' => '5' },
'user2' => { 'path' => '/tmp/','days' => '3' }
}
in a external file as settings?
How can I include this into my script?
The most common way to store configuration data in Ruby is to use YAML:
settings.yml
user1:
path: /
days: 5
user2:
path: /tmp/
days: 3
Then load it in your code like this:
require 'yaml'
settings = YAML::load_file "settings.yml"
puts settings.inspect
You can create the YAML file using to_yaml:
File.open("settings.yml", "w") do |file|
file.write settings.to_yaml
end
That said, you can include straight Ruby code also, using load:
load "settings.rb"
However, you can't access local variables outside the file, so you would have to change your code to use an instance variable or a global variable:
settings.rb
SETTINGS = {
'user1' => { 'path' => '/','days' => '5' },
'user2' => { 'path' => '/tmp/','days' => '3' }
}
#settings = { 'foo' => 1, 'bar' => 2 }
Then load it thus:
load "settings.rb"
puts SETTINGS.inspect
puts #settings.inspect
you can also use Marshal
settings = {
'user1' => { 'path' => '/','days' => '5' },
'user2' => { 'path' => '/tmp/','days' => '3' }
}
data=Marshal.dump(settings)
open('output', 'wb') { |f| f.puts data }
data=File.read("output")
p Marshal.load(data)
A really simple one is to use eval.
config.txt
{
'user1' => { 'path' => '/','days' => '5' },
'user2' => { 'path' => '/tmp/','days' => '3' }
}
program.rb
configuration = eval(File.read("./config.txt"))
puts configuration['user1']