puppet apply not working - macos

I am trying to puppet locally in my mac(OS X). I installed latest versions of puppet, hiera and facter. I created a module with the following structure
$ find .
.
./files
./manifests
./manifests/init.pp
./templates
and contents of hello_world/manifests/init.pp
$ cat manifests/init.pp
class hello_world {
file {'/tmp/itworks':
ensure => directory,
}
}
but nothing happens when I run puppet apply hello_world/manifests/init.pp

You define a class but never include it. (The class does not get declared.)
Note that modules are not usually applied directly. Instead, you apply a manifest that includes a class from the module (often, the class that is named after the module and automagically located in module_name/manifests/init.pp. E.g.
puppet apply -e 'include hello_world'
Note that the hello_world/ directory must be located in your $modulepath (usually /etc/puppet/modules for the open source variant.

You can try :
puppet apply -e 'include hello_world'
or for a dry run
puppet apply -e 'include hello_world' --noop
For more puppet apply, see manual page : http://docs.puppetlabs.com/man/apply.html

Related

List modules in shell like in erlang

I have code in erlang for listing module path for a module:
code:get_object_code(Module)
Do we have anything similar in shell?
I know we can list modules in shell by :
module list
But it specifically does not give the module path for particular module name
I have tried with:
module show module_name
output: ModuleCmd_Display.c(151):ERROR:105: Unable to locate a modulefile for 'module_name'
This seems to work if you give the name as returned by module list. For example, I have two active modules:
$ module list
Currently Loaded Modulefiles:
1) module-info 2) module-git
I can ask for information about, say, module-git, and the output contains the file name of the module, including directory:
$ module show module-git
-------------------------------------------------------------------
/home/magnus/modules/modulefiles/module-git:
module-whatis {get last version of the module sources from GitHub}
set-alias get-modules {git clone git://github.com/cea-hpc/modules.git && cd modules}
-------------------------------------------------------------------

Puppet - how to pass arguments to the command line

I am newbie to puppet and I wonder how I can pass arguments to the command line. I will explain myself:
This is the command that I'm running (puppet apply):
C:>puppet apply --environment test -l C:\Puppet_logs\log.log C:\ProgramData\PuppetLabs\code\environments\test\manifests\site.pp
Site.pp:
File { backup => false }
node default {
include 'tn'
}
It means that I am running 'tn' which is one of the modules in my puppet project.
For example,
I have these modules in my puppet project:
tn
ps
av
So to run each module I need to go to this site.pp file and change it to
include 'ps'
or
include 'av'
My question is -
How do I pass these modules as arguments to the puppet apply command?
I know that I can create 3 .pp files that each one contains one module (ps, av, tn)
And then my command will look like:
puppet apply --environment test -l C:\Puppet_logs\log.log C:\ProgramData\PuppetLabs\code\environments\test\manifests\ps.pp
puppet apply --environment test -l C:\Puppet_logs\log.log C:\ProgramData\PuppetLabs\code\environments\test\manifests\av.pp
puppet apply --environment test -l C:\Puppet_logs\log.log C:\ProgramData\PuppetLabs\code\environments\test\manifests\tn.pp
But, I think it's not a good solution..
Is there another way to pass these modules as arguments to the puppet apply?
If I didn't mention - each module is responsible for different actions.
thanks !!!
I know that I can create 3 .pp files that each one contains one module
(ps, av, tn)
[...]
But, I think it's not a good solution.
Why isn't it a good solution? It seems perfectly sensible to me that if you have three different things you want to be able to do, then you have a separate file to use to accomplish each.
Nevertheless, if your modules do not use each other, then you could probably accomplish what you describe by relying on tags. Have your site manifest include all three modules:
File { backup => false }
node default {
include 'tn'
include 'ps'
include 'av'
}
Then use the --tags option to select only one of those modules and all the other classes it brings in:
puppet apply --tags ps --environment test -l C:\Puppet_logs\log.log C:\ProgramData\PuppetLabs\code\environments\test\manifests\site.pp
A pp file is a class file not a module, a module contains the classes and anything else needed to support/test those classes, take a look at https://puppet.com/docs/puppet/5.5/modules_fundamentals.html.
Look at how modules are laid out on https://forge.puppet.com/
It’s well worth looking at the PDK https://puppet.com/docs/pdk/1.x/pdk.html as it'll build a module for you, you just need to add the classes.
In your case you probably want to create a new module (let’s call it mymodule) and in that module put all your tn.pp ps.pp and av.pp class files under the C:\ProgramData\PuppetLabs\code\environments\test\modules\mymodule\manifests directory.
Then for local testing use the examples pattern, so in your module you’ll have an examples directory and in there you might have a file called ps.pp which would contain include mymodule::ps to include that ps.pp class file.
The aim of the examples directory is to give you a method of passing in parameters for local testing.
Back in your site.pp file you’d apply is with:
Node default {
Include mymodule::ps
}
So now you want to apply different classes to the nodes and there you hit the world of node classification and there are many ways you can do that. In your case I think you’re probably doing this on a small scale so you’d have;
Node psserver.example.com {
Include mymodule::ps
}
Node tnserver.example.com {
Include mymodule::tn
}
Have a look at some of the online training https://puppet.com/learning-training/kits/puppet-language-basics

Puppet installing software defined in another node's definition

I am using Puppet Enterprise.
# puppet master --version
4.8.1
Manifests dir (/etc/puppetlabs/code/environments/production/manifests) contains the following:
iis.pp
rds.pp
site.pp
I have a node definition in site.pp as shown below:
# cat site.pp
node 'box A' {
include iis
}
Now the issue i am facing is that if i create a new node (say, box B) and add it to site.pp by creating a blank definition as shown below, it still installs softwares that are actually part of another node ('box A' in this case) definition.
node 'box B' { }
I don't have any include statement in site.pp defined outside the above two node definitions.
Why is this happening?
UPDATE:
# cat iis.pp
$iis_features = ['Web-Server','Web-WebServer','Web-Asp-Net45','Web-ISAPI-Ext','Web-ISAPI-Filter','NET-Framework-45-ASPNET']
windowsfeature { $iis_features:
ensure => present,
}
Since Puppet 4, all files in the top-level environment manifests/ directory will be automatically loaded. Usually this is so you can define different node definitions or classes and have them all loaded without using the import directive (used in Puppet 2 and 3).
In your case, iis.pp, rds.pp and site.pp are parsed and used on every node. (Directories: The main manifest(s) has some more info on how this is configured.)
To fix it, use Puppet classes to group your IIS configuration (the windowsfeature resources) into an iis class - then your include iis will only use this configuration on "box A".
Change iis.pp to define a class:
class iis {
$iis_features = ['Web-Server','Web-WebServer','Web-Asp-Net45','Web-ISAPI-Ext','Web-ISAPI-Filter','NET-Framework-45-ASPNET']
windowsfeature { $iis_features:
ensure => present,
}
}
Ideally, move iis.pp to /etc/puppetlabs/code/environments/production/modules/iis/manifests/init.pp to be in the standard module location. This provides better performance as Puppet doesn't need to read iis.pp until you use include iis.

Vagrant Puppet Class Not Found Error

I am getting the message:
Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class git at /tmp/vagrant-puppet-1/manifests/site.pp:15 on node vagrant-ubuntu-precise-64.wp.comcast.net
Probably the best idea is to see this in action. I have created a GitHub repo of the exact manifest I am using. It is here:
https://github.com/jamorat/puppet-example
The manifests and git module are there. If you have Vagrant, this can be vagrant up and you will see the error for yourself. Would be cool to either receive an answer here and/or also as a commit (for which credit would still be given here for answer.)
Thank you so much!
You need to configure vagrant with the puppet module path. On a side note, you would also usually keep the manifest and module folder in the same folder, instead of modules inside manifests.
This:
class{ git:
svn => 'installed',
gui => 'installed',
}
is telling puppet to create a resource based on the class named git that has 2 parameters: svn and gui. Such a class declaration doesn't exist anywhere in what you've posted. If it were, it would look something like:
class git ($svn, $gui) {
package {'svn':
ensure => $svn,
}
# Whatever 'gui' is, making package b/c use of "installed"
package {'gui':
ensure => $gui,
}
}
Alternative is to declare a class and include it using the "include" directive.
Recommend a good reading of Language: Classes

In perl, how do I use modules created with module-starter in the same directory?

I have a bunch of scripts which I want to refactor into modules. This is the first time I'm doing something like this. I read online and Module::Starter seems to be one of the preferred ways of creating new modules. But how should I, during development, use the modules from other unrelated scripts? I don't want to build/install every module every time I modify it. Furthermore, how should I distribute scripts with modules in the same directory? (Ie, I want to distribute an application script.pl with Foo::Bar and Foo::Baz in the same tar ball, and I want 'perl script.pl' to just-work, especially on strawberry). Any hints?
> module-starter --module=Foo::Bar
Created Foo-Bar
Created Foo-Bar/lib/Foo
Created Foo-Bar/lib/Foo/Bar.pm
Created Foo-Bar/t
Created Foo-Bar/t/pod-coverage.t
Created Foo-Bar/t/pod.t
Created Foo-Bar/t/manifest.t
Created Foo-Bar/t/boilerplate.t
Created Foo-Bar/t/00-load.t
Created Foo-Bar/ignore.txt
Created Foo-Bar/Makefile.PL
Created Foo-Bar/Changes
Created Foo-Bar/README
Created Foo-Bar/MANIFEST
Created starter directories and files
> perl -MFoo::Bar -w -e ''
Can't locate Foo/Bar.pm in #INC (#INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .).
BEGIN failed--compilation aborted.
Add the directories you want to be included in the Perl Module search using the PERL5LIB environment variable:
export PERL5LIB=/somedir

Resources