Ask Your Question

puppet apply

asked 2017-02-16 08:51:37 -0500

G'day, newbie question, why is it stated in puppet training material that it's advised to use the example directory to declare the classes and run puppet apply against the files in the examples dir instead of the manifests ? The explanation given was that it will not apply any changes if puppet apply is run against files in the manifests dir. How does it get differentiated ? puppet should anyway be looking at the facts for a config drift which i think still could be achieved with files in the manifests. I know i'm wrong :) can someone explain this please ? tia MB

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-17 07:17:41 -0500

DarylW gravatar image

When you have manifests from a module, they are just class definitions. You need to invoke the class to actually get any changes. For example.

# ~/example_modules/foo/manifests/init.pp
class foo (){ 
  file { '/tmp/foo':
    content => 'Hello World',

If you run puppet apply ~/example_modules/foo/manifests/init.pp, there will be no classes applied.

If you run puppet apply -e 'include foo' --modulepath ~/example_modules/ You will see that it creates the file /tmp/foo with the content of 'Hello World'.

The -e stands for 'expression', and you can place any valid puppet code in there, though it can get cumbersome with shellquoting and things. That's why it's better to write out example usage files in mymodule/examples/myexample.pp That way you can test applying your examples by doing something like this (if you have all modules you depend on in ~/example_modules, for instance): puppet apply ~/example_modules/foo/examples/no_param_foo.pp --modulepath ~/example_modules/

edit flag offensive delete link more


@DarylW thanks for the detailed explanation to help clarify.

Mbarlow gravatar imageMbarlow ( 2017-02-18 06:26:40 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-02-16 08:51:37 -0500

Seen: 35 times

Last updated: Feb 17