Puppet creating file on an agent - puppet

I'm running a puppet code that create a file with text, it's working when I'm running it locally (with puppet apply <.pp file> on the same machine) but not working when I'm running the code on an agent from a puppet master server (with puppet agent -t on the manifests directory) my code:
node default {
file { '/test544/newdirha1': #the path of the new file
ensure => 'present',
content => 'this is the content', #this text will be inside the file
owner => 'root',
group => 'root',
mode => '0644',
}
}

The problem is that the master does not read or process your manifest file at all.
Puppet 3.8 is obsolete and unsupported. The latest us Puppet 6.2, and since you're just getting going I recommend starting there. The expected layout and behavior of that and other more recent Puppet versions differ in some import and relevant ways, but in Puppet 3, the starting point for the master's processing is a single file, the "site manifest", which by default is /etc/puppet/manifests/site.pp.
Your master having neither a site manifest nor an external node classifier to rely upon, it will not assign any classes or resources to any node. It will generate only empty catalogs, which is exactly what you observe. Your manifest woot3.pp is ignored. The simplest and most direct way to solve the problem would be to rename woot3.pp to site.pp.

Related

Puppet agent can't be deployed module from master

I'm just start learning Puppet, really new to this world. I'm using puppet 2.7.26 on my two learning VMs --
puppet-master 192.168.160.131
eisen-suse11 192.168.160.129
Follow the turial, I've signed the node "eisen-suse11" to puppet-master successfully--
puppet-master:/etc/puppet/modules/motd/manifests # puppet cert --list --all
+ "eisen-suse11" (A0:7F:E2:77:30:9A:96:E3:79:FD:F7:1E:59:35:5B:1E)
+ "puppet-master" (38:90:B5:8A:68:8A:A7:44:8A:2F:07:D3:F3:AC:E8:80) (alt names: "DNS:puppet", "DNS:puppet-master", "DNS:puppet-master.suse11", "DNS:puppet.suse11")
+ "puppet-master.suse11" (5D:9E:A4:D9:0C:5F:69:07:FA:55:13:C3:38:6D:9B:26)
Then follow the book, I write a module -- motd -- which should put a file to client node --
puppet-master:/etc/puppet/modules/motd/manifests # cat init.pp
class motd{
package{ 'setup':
ensure => present,
}
file{ '/etc/motd':
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
source => "puppet://$puppetserver/modules/motd/etc/motd",
require => Package['setup']
}
}
puppet-master:/etc/puppet/modules/motd/manifests # cat site.pp
$puppetserver='puppet-master.suse11'
node 'eisen-suse11'{
include motd
}
But when I tested "puppet agent --test --trace" on the client node -- eisen-suse11 --- it's all quiet --
eisen-suse11:~ # puppet agent --test --trace
info: Caching catalog for eisen-suse11
info: Applying configuration version '1633779962'
notice: Finished catalog run in 0.01 seconds
eisen-suse11:~ # ls /etc/motd
ls: cannot access /etc/motd: No such file or directory
That "/etc/motd" is not copied from puppet-master --
Does anyone can help? Any idea would be appreciated.
RGS
Eisen
The problem is that your node is receiving an empty catalog, which is happening because you put your site.pp file in the wrong place. Puppet will not find it inside the module. It has been a very long time since I wrote code for Puppet 2 (and I hung on to that version much longer than was healthy), but as I recall, the correct directory for that file would be /etc/puppet/manifests.
But again, as I wrote in comments, Puppet 2 is utterly obsolete and well past the end of its life. Ditch it, and also ditch any books you have that teach it. The only reason I can think of to learn this version of Puppet is that you have an existing legacy infrastructure that you are obligated to maintain, but if you are faced with such a Puppet code base in 2021 then it would be best to rewrite from scratch for Puppet 7.

How to provide a startup service file in Puppet

We have RedHat 7.2 Linux OS and use puppet to perform our tasks. I am using puppet to install some software, which has worked fine and now the final step is to create an OS level service. In earlier versions of RHEL, we used chkconfig but that has been replaced with systemctl. Of course, the recommended way of performing this task is using a service. Since this is a custom software, I have my own startup script that I usually copy over to /etc/init.d, run chkconfig and then startup the service. How do I perform these tasks via Puppet for RedHat 7.2 OS ? I only want to create the service (not start it up or anything). This way, when the server reboots, the service will startup the app.
EDIT :
#redstonemercury for RHEL 7 I would think the following would be required. But your suggestion definitely helps as I was thinking along the same lines.
https://serverfault.com/questions/814611/puppet-generated-systemd-unit-files
file { '/lib/systemd/system/myservice.service':
mode => '0644',
owner => 'root',
group => 'root',
content => template('modulename/myservice.systemd.erb'),
}~>
exec { 'myservice-systemd-reload':
command => 'systemctl daemon-reload',
path => [ '/usr/bin', '/bin', '/usr/sbin' ],
refreshonly => true,
}
In puppet, use a package resource to install the package (assuming it's in repos that you're declaring already), then use a file resource to declare the /etc/init.d file, and put require => Package[<package_resource_name>] as a parameter in the file declaration to ensure the custom file gets created after the package has installed (so doesn't potentially get overwritten by the package's /etc/init.d file). E.g.:
package { 'mypackage':
ensure => present,
}
file { '/etc/init.d/mypackage':
ensure => present,
content => template('mypackage/myinitd'),
require => Package['mypackage'],
}
This is if you want to use a template. For a file, instead of content use source: source => puppet://modules/mypackage/myinitd

How do I run a Puppet Manifest on a Windows server with Puppet Agent?

I have done it in the past. I don't know why I cannot do it this way below. I am using CentOS 7 for the Puppet Master server. I am using Windows Server 2012 with Puppet Agent.
All the content below was taken from the Puppet Master server. Here is site.pp (which is in /etc/puppet/manifests):
node 'fqdnOfWindowsServer' { import 'good.pp'}
node 'fqdnOfLinuxServer' {}
Here is good.pp (which is in /etc/puppet/manifests):
file { 'c:/fun.ps1':
ensure => 'present',
source => '/tmp/special.ps1',
source_permissions => 'ignore',
}
Here is what happens when I run puppet agent -t:
...Caching catalog for fqdnOfLinuxServer... Error: Failed to apply
catalog: Parameter path failed on File[c:/fun.ps1]: File paths must be
fully qualified, not 'c:/fun.ps1' at /etc/puppet/manifests/good.pp:5
How do I input a fully qualified path? It seems to be having a problem with a Windows server as the Puppet Agent. Paths are different from Linux Puppet Agents.
From what I can make of the error message, you're trying to create a Windows file resource on a Linux server (the error mentions caching catalog for fqdnOfLinuxServer). If that's the case, the error message makes sense because on Linux, the agent expects file paths to start with a forward slash.

Puppet transfer files to agent

I am playing around with puppet and am trying to copy a file from my local directory (my laptop) on to my puppet agent. I have two VM's running, one is puppet master and one is puppet agent. I looked up at this answer here but it seems like it was an older version on puppet. I am running puppet 3.4.3 . I have gone through the pro puppet book and the puppet tutorials but find them way to confusing (the former having very glaring typos). It would be BIG help if someone helped me out with the process in simple steps. This is what I have till now.
I created a folder named my_module in /etc/puppet/.
In /etc/puppet/my_module is created two folders files, manifests and a file init.pp .
Init.pp looks like this:
class myfile {
file { "/home/me/myfolder/file.py":
mode => "0440",
owner => 'root',
group => 'root',
source => 'puppet:///modules/module_name/datas.xls',
}
}
I then copied the file file.py to the files folder I created above. I am unsure how to proceed after this step. Any help?
please read this documentation regarding creating your own modules. The module you created is in the wrong location right now. Should be /etc/puppet/modules or wherever the modulepath in /etc/puppet/puppet.conf points to on the puppet master.
The file given with source => 'puppet:///modules/module_name/datas.xls' is the one which will be placed in /home/me/myfolder/file.py on the client where you run the puppet agent -t command to rollout your changes.
Another good source for examples how to use the standard builtin puppet features is Type Reference of puppetlabs.

Puppet fileserver - Could not evaluate

I am working on trying to copying files from my puppetmaster to my webserver, which is not working.
On my puppetmaster I have edited the file fileserver.conf and added:
[extra_files]
path /etc/puppet/files
allow *
After that, restarted puppetmaster and puppet on the puppetmaster.
I have an test.txt in the /etc/puppet/files folder
On the webserver I have this apache2.pp script
file { "/test.txt":
mode => "600",
owner => 'root',
group => 'root',
ensure => present,
source => "puppet:///files/test.txt",
}
I am receiving this error, which I am really unsure how to solve:
**Error: /Stage[main]/Main/File[/test.txt]: Could not evaluate: Could not retrieve information from environment production source(s)**
Hope someone can maybe help me with some steps to troubleshoot what is going wrong.
According to description in fileserver.conf:
# [extra_files]
# path /etc/puppet/files
# allow *
#
# In the example above, anything in /etc/puppet/files/<file name> would be
# available to authenticated nodes at puppet:///extra_files/<file name>.
#
change
source => "puppet:///files/test.txt",
to
source => "puppet:///extra_files/test.txt",
Don't use file server mounts unless you have a very good reason to do so.
Instead, create a module that holds the file you need to sync, such as module webserver
mkdir -p /etc/puppet/modules/webserver/files
In your file resource, reference the file as follows:
source => 'puppet:///modules/webserver/test.txt'
Be careful not to include files in the URL of files that are retrieved from within modules.

Resources