Ask Your Question
0

Where is the proper place to put templates using roles and profiles practices?

asked 2016-09-16 09:26:43 -0500

wfsaxton gravatar image

I'm trying to create a template for use by the motd class in my base profile. I'm not quite sure where I should put it though. I'm also having trouble referencing the path from with the class.

Here is my control data structure:

/site/profile/manifests
--> base.pp
--> templates/
----> motd.erb

base.pp:

class profile::base {
  class { 'motd':
    template => 'templates/motd.erb'
  }
}

But I get the following when trying to deploy it:

Could not find template 'templates/motd.erb' at /etc/puppetlabs/code/environments/wsaxton/modules/motd/manifests/init.pp:22:21 on node drmbksca.local

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
2

answered 2016-09-19 09:50:31 -0500

reesek gravatar image

Create a templates subdirectory under the profile dir.

➜  puppet-control git:(dev) tree site
site
├── profile
│   ├── templates
│   │   └── ca_cert
│   │       └── rootCA.cer.erb
│   └── manifests
│       ├── ca_cert.pp
└── role
    └── manifests
        ├── jenkins_agent.pp
        ├── rabbitmq.pp
        └── webserver.pp

class profile::ca_cert () {
  include ca_cert
  ca_cert::ca { 'rootCA':
    ensure => 'trusted',
    content => template('profile/ca_cert/rootCA.cer.erb'),
  }
}
➜  puppet-control git:(dev)
edit flag offensive delete link more

Comments

Looks like I beat you by 4 minutes! Unfortunately, since I'm not a new member I can't actually vote for my own answer so I'll just accept this one.

wfsaxton gravatar imagewfsaxton ( 2016-09-19 10:01:26 -0500 )edit
1

answered 2016-09-16 14:45:28 -0500

DarylW gravatar image

It appears that you are programming your profile directly into site.pp, which is part of your problem. If you aren't using any kind of External Node Classifier (ENC), you should be putting your role definitions in the nodes.pp file for your particular node.

Roles and profiles are just organizational conventions... under the hood it is just a special form of a module.

https://docs.puppet.com/guides/moduleguides/bgtm.html https://docs.puppet.com/puppet/latest...fundamentals.html

In all modules, they have a layout like

mymodule
-> manifests/
->              -> init.pp
-> templates/
->              -> motd.erb

You would then need to make sure your module containing your roles/profiles is on your module path, either global or in your environment (varies depending on if you are in puppet 3.x or 4.x), and then you would need to include your role in your nodes.pp, where you are classifying what classes are going to run on that node.

I also recently stumbled upon this (sadly incomplete) ebook, that has a really good base example of some good design patterns for making your modules.

If you need more specific help, let us know!

edit flag offensive delete link more

Comments

I don't think whether I use ENC or nodes.pp is relevant to this issue, is it? My setup is exactly the same as the control-repo project created by puppetlabs: https://github.com/puppetlabs/control-repo

wfsaxton gravatar imagewfsaxton ( 2016-09-19 09:10:01 -0500 )edit

I'm just trying to figure out where I should put my motd template if I'm duplicating their "recommended" control repo structure.

wfsaxton gravatar imagewfsaxton ( 2016-09-19 09:27:35 -0500 )edit
1

Thanks to your answer about the proper directory structure (manifiests/templates being peers) in combination with the proper syntax for how to reference a template, I was able to figure it out. Thanks!

wfsaxton gravatar imagewfsaxton ( 2016-09-19 09:47:25 -0500 )edit
0

answered 2016-09-19 09:45:42 -0500

wfsaxton gravatar image

Using some of the information given in @DarylW's answer, I figured it out:

Restructure the files to:

/site/profile/manifests
--> base.pp
/site/profile/templates/
--> motd.erb

Then change base.pp to:

class profile::base {
  class { 'motd':
    template => 'profile/motd.erb'
  }
}
edit flag offensive delete link more

Comments

Sorry, I didn't see your comments, glad it helped you figure out your answer!

DarylW gravatar imageDarylW ( 2016-09-19 11:30:06 -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

Stats

Asked: 2016-09-16 09:26:43 -0500

Seen: 206 times

Last updated: Sep 19 '16