Consider the following puppet config snippet:
file { "/opt/app/${name}/traces" :
ensure => directory,
owner => 'appuser',
group => 'appuser',
ignore => [ '*.tra' ],
backup => false,
recurse => false
}
The folder will contain "${name}..tra" files and I don't want puppet to take care of these files.
When calling strace or lsof against the puppet client, I can see it still tries to do something with these files (probably checksuming, according to the time spent on each file).
Thanks a lot,
Adam.
Related
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
I am working a Puppet manifest that configures a router in the equipment that I support. The router runs pretty much plain vanilla Debian 8 or 9.
The problem is in the way the SSD on the router is partitioned.I am not able to change the partitioning, so have to work around the fact that the root file system is small. I have found a solution that I am trying to implement in Puppet but my first attempt doesn't feel right to me so I thought I would ask the community.
I have been and am reading the Puppet docs. Unfortunately I don't have my router hand to play with today so I am unable to test my current solution.
My issue is that by df -H the root file system is at 95% capacity and puppet is failing complaining about not enough space. Because of quirky decisions made a long time ago by others, the /opt/ file system is 5 times the size of / and is at 10% usage.
So my solution, tested manually, is to move /var/cache/apt/archives/ to /opt/apt-archives and then create a symlink using:
ln -s /opt/apt-archives /var/cache/apt/archives
That works and allows the puppet run to finish without errors.
My challenge is to implement this operation in a Puppet class
class bh::profiles::move_files {
$source_dir = '/var/cache/apt/archives'
$target_dir = '/opt/apt-cache'
file { $targetDir :
ensure => 'directory',
source => "file://${source_dir}",
recurse => true,
before => File[$source_dir]
}
file { $source_dir :
ensure => 'absent',
purge => true,
resurse => true,
force => true,
ensure => link,
target => "file://${target_dir}"
}
}
It just doesn't feel right to have ensure repeated in one file resource. And based on what I understand of creating links in puppet I would need the same name for the file resource that deletes the archives directory and the one that creates the link.
What am I missing?
Use exec:
exec { 'Link /var/cache/apt/archives':
command => 'mv /var/cache/apt/archives /opt/apt-archives
ln -s /opt/apt-archives /var/cache/apt/archives',
path => '/bin',
unless => 'test -L /var/cache/apt/archives',
}
Note that Puppet was not really designed to solve automation problems like this one, although using Exec it is possible to do most things anyway.
Your solution sounds like a work-around and it is therefore totally ok to implement a work-around using Exec. I would say, just make sure you add some comments explaining why you had to do something like this.
I have a file at some web URL (http://www.somewhere.com/something.tar.gz).
This is direct download link.
I need a puppet code that would download this file, extract it and install the file.
Can we do this using package {} in puppet?
There isn't really an intrinsic provider for the package type that understands tarballs. There is, however, this VoxPopuli module: https://forge.puppet.com/puppet/archive which was recently Puppet certified and should do what you need.
Note under their usage example it could be modified for your needs like:
archive { '/tmp/something':
ensure => present,
extract => true,
extract_path => '/tmp',
source => 'http://www.somewhere.com/something.tar.gz',
checksum => 'checksum hash',
checksum_type => 'sha1',
creates => '/tmp/something',
cleanup => true,
}
I am using following script part to unzip my zip file. But the problem is it unzips the file always into a readonly folder. How can this be fixed.
exec { "install appliction server to pc":
command => 'unzip wso2as-5.2.1.zip',
cwd => '/home/malintha/adikari3/',
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
logoutput => true,
timeout => 3600,
require => File['/home/malintha/adikari3/wso2as-5.2.1.zip'],
}
There are three parameters to the exec type, of which you should use at least one, to control when and when not to run
onlyif
unless
creates
The unzipping of an archive typically lends itself to a creates solution
exec { "unzip-file":
cwd => "/path/for/extraction",
creates => "/path/for/extraction/software-x.y",
...
}
assuming that the zip extracts into a directory tree rooted at software-x.y.
For more details, see the reference documentation.
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"],
}