Setting file mode with Puppet - puppet

I am trying to set the file mode with puppet but it is not being set.
file { 'create script':
ensure => file,
path => "${test_script}/test_script.sh",
content => template('test/test_script.sh.erb'),
require => File[$test_script],
mode => '0775'
}
It creates the file correctly but the mode remains the default 0644.

Figured out what was causing the issue. The file was being copied over to another system and required
source_permissions => true
to keep the permissions and not use puppets.

Related

How to copy list of files using puppet

In puppet is it possible to copy of list of files
Tried below code, but didn't work
$list_files = ['file1','file2','file2']
file { $list_files:
ensure => present,
path => /tmp,
source => 'puppet:///modules/$module_name/list_file_dir/$list_files',
}
any Suggestions?
As others have said you can use the each switch e.g.
['file1','file2','file2'].each |$flie| {
file{ "/tmp/${file}":
ensure => file,
source => "puppet:///modules/$module_name/list_file_dir/${file}",
}
}
however it is also worth noting that you can pass a directory to both the destination and the source parameter e.g. if you have the directory puppet:///modules/$module_name/list_file_dir on your puppet master with the files ['file1','file2','file2'] then you can copy them all to temp using the following
file { '/tmp':
ensure => directory,
source => 'puppet:///modules/$module_name/list_file_dir',
recurse => remote,
}
using recurse => remote remote ensures puppet only manages files which exist in the remote location (i.e. the puppetmaster)
https://puppet.com/docs/puppet/7/types/file.html#file-attribute-recurse

Setting multiple environment variables using Puppet

Currently I am using
file {"/etc/profile.d/setjvmparams.sh":
ensure => file,
owner => root,
source => "puppet:///modules/java/setjvmparams.sh",
}
But I want to remove dependency of my module on external files. Is there a way out to set env variable?
Note: setjvmparams.sh has 3 lines.
I want to put paths in /etc/profile.d and source it.

Logstash: since_db not getting created

Was playing with the since_db option and it appears that the sincedb file isn't getting created. Below is my Logstash File configuration. I have verified that I can create the file manually so there is no permission issue. Would appreciate if anyone can throw more light on the same.
input {
file {
path => "/home/tom/fileData/*.log"
type => "log"
sincedb_path => "/home/tom/sincedb"
start_position => beginning
}
}
Can the user running logstash write to the sincedb_path location, if not that is what needs to get fixed. Other than that, your logstash configuration should work fine.

Including a definition by variable

I'm working on putting together some puppet scripts - I've got a list of services (probably about 20 or so) that need to be deployed in very similar fashions.
Stop existing service
Get package out of nexus
Unzip it into directory
Set configuration variables
Start service
The problem is #4. Each service has a slightly different configuration. I'd like to use augeas to set the configurations for each service, and it seemed to make sense to make a definition for each service's config, and then that definition loaded in the main service definition.
So, I've got something like the following:
definition service ($serviceName) {
//stopping, wget, unzip
config[downcase($serviceName)] { "${servicename}_config":
serviceName => $serviceName
}
//start
}
Then, I've got (for example) in the config module's manifest folder "foo.pp"
definition config::foo {
//set some stuff
}
This isn't working due to various rules that I'm sure I've broken but are unaware of. Is there a 'standard' way of doing what I'm trying to do?
You could try the code below. You can put all these in a define type with variables for service name myserv. I would suggest of using templates to set the configuration rather than augeas... easier to control.
exec { "stop_myserv" :
command => "service stop myserv",
path => "/path/to/command/service",
refreshonly => true,
}
exec { "get_pkg_from_nexus" :
command => "/command/to/do/the/above && unzip to/dirctory",
path => "/path/to/command",
require => Exec["stop_myserv"],
}
file { "set_configuration" :
path => "/etc/somewhere/file",
content => template("modulename/file.erb"),
mode => "999",
group => "jiut",
owner => "muit",
require => Exec["get_pkg_from_nexus"],
}
service { "myserv" :
ensure => running,
subscribe => File["set_configuration"],
}

Is this the correct way to change a config file using puppet?

I have a rails app and I'd like to change the ./config/environment/production.rb file to have a different config based on what I want that server to do.
So, I'm going into the .rb file from the .pp file and changing some strings then restarting the service. This just seems really poor form to me. Is there a better way to do this? I've been asked to deliver 1 RPM and change the config via puppet, so...
class Cloud-widget($MServer, $GoogleEarthServer, $CSever) {
package { "Cloud-widget":
ensure => installed
}
service { "Cloud-widget":
ensure => running,
}
<%
file_names = ['./config/environment/production.rb']
file_names.each do |file_name|
puts text.gsub(/.*config.mserver(.*)/, "config.mserver_root = \"#{$Merver}\"")
puts text.gsub(/.*config.google_earth_url(.*)/, "config.google_earth_url( = \"#{$GoogleEarthServer}\"")
puts text.gsub(/.*config.cserver_base_url(.*)/, "config.cserver_base_url = \"#{$CServer}\"")
end
File.open(file_name, "w") {|file| file.puts output_of_gsub}
%>
service { Cloud-widget:
ensure => running,
subscribe => File["./config/environment/production.rb"],
}
}
No, that is not a good way to achieve what you need.
You could look at templates and generate the config files that way. That way, you can use variables in the config file.
If you need create conf from pattern you should use INI-file module from Puppetlabs
ini_setting { "sample setting":
path => '/tmp/foo.ini',
section => 'foo',
setting => 'foosetting',
value => 'FOO!',
ensure => present,
}
install this module from puppet:
puppet module install cprice404-inifile

Resources