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 ")"
Related
Im trying to create an API connection in Logstash and push the data to elasticsearch.
Both Elasticsearch and Logstash versions are 7.1.0.
Below id the logstash file:
input {
http_poller {
urls => {
test2 => {
method => get
user => "readonly"
password => "mypass#123"
url => "https://nfr.saas.appdynamics.com/controller/rest/applications?output=JSON
headers => {
Accept => "application/json"
}
}
}
request_timeout => 60
# Supports "cron", "every", "at" and "in" schedules by rufus scheduler
schedule => { cron => "* * * * * UTC"}
codec => "json"
# A hash of request metadata info (timing, response headers, etc.) will be sent here
metadata_target => "http_poller_metadata"
}
}
output {
elasticsearch { hosts => ["localhost:9200"] }
stdout { codec => rubydebug }
}
I am receiving an error:
An unexpected error occurred! {:error=>java.nio.file.AccessDeniedException: D:\logstash-7.1.0\logsta
sh-7.1.0\data\.lock, :backtrace=>["sun.nio.fs.WindowsException.translateToIOExce
ption(sun/nio/fs/WindowsException.java:83)", "sun.nio.fs.WindowsException.rethro
wAsIOException(sun/nio/fs/WindowsException.java:97)", "sun.nio.fs.WindowsException
Edit 1: post giving permissions to data folder suggested by #apt-get_install_skill , below is the timeout error i received:
[0] "_http_request_failure"
],
"http_request_failure" => {
"request" => {
"method" => "get",
"url" => "https://nfr.saas.appdynamics.com/controller/rest/applications?output=JSON",
"headers" => {
"Accept" => "application/json"
},
"auth" => {
"user" => "readonly",
"pass" => "mypass#123",
"eager" => true
}
},
"runtime_seconds" => 10.004,
"name" => "test2",
"error" => "connect timed out",
"backtrace" => nil
}
}
Im new to APIs, and I'm not sure how to simply fetch the output from the URL. Could you help me on getting this corrected?
The URL works when i hit it on my browser.
The problem is not the elasticsearch output but more the permissions of the file
D:\logstash-7.1.0\logstash-7.1.0\data\.lock
as stated in the stacktrace:
error=>java.nio.file.AccessDeniedException: D:\logstash-7.1.0\logstash-7.1.0\data\.lock, :backtrace=>["sun.nio.fs.WindowsException.translateToIOExce
ption(sun/nio/fs/WindowsException.java:83)", "sun.nio.fs.WindowsException.rethro
wAsIOException(sun/nio/fs/WindowsException.java:97)", "sun.nio.fs.WindowsException
You need to make sure that the user that executes logstash has the permissions to read and write this file.
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.
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?
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']