Can you make submodules in puppet, for instance have...
puppet_root
- modules
- module_1
- submodule
- manifests
- init.pp
I've tried this and puppet doesn't seem to like it. I could change my submodule init.pp's into more descriptive filenames and get rid of the directories all together but some of the modules have more than one file and that will clutter things up.
The reason I'm doing this is to put all of the OS tools together into one "super" module, so it can be more self-documenting: eg. os_tools::lsof, etc.
puppet structure goes like this :
/etc/puppet/modules/modulename/manifests/init.pp
class modulename{
-----
}
submodule1 and submodule2 can be directories inside /etc/puppet/modules/modulename/manifests/
and each of them can contain .pp files. for example:
/etc/puppet/modules/modulename/manifests/submodule1/foo.pp
class modulename::submodule1::foo{
notify{"I am in modulename->submodule1->foo":}
}
You can include the class like this:
include modulename::submodule1::foo
Related
I am trying to build Terragrunt script for deploying the infrastructure to Microsoft Azure cloud. Things are working fairly well but I am not able to figure out one thing.
The structure of setup looks something like this:
rootdir
terragrunt.hcl
someconfig.hcl
module1dir
terragrunt.hcl
config.auto.tfvars.json
module2dir
terragrunt.hcl
config.auto.tfvars.json
module3dir
terragrunt.hcl
config.auto.tfvars.json
Each module is configured using Terraform autoload tfvars feature with config.auto.tfvars.json. What I would like is to have these files outside of the directory structure and somehow instruct Terragrunt to apply correct external configuration file to correct submodule.
Any ideas?
I solved this in the following manner:
Define environment variable you plan on using which should contain location to the configuration files. Make sure it is not clashing with anything existing. In this example we will use TGR_CFGDIR. In the external configuration module place the module configuration files and make sure they are properly named. Each file should be named as the module and end with .auto.tfvars.json. So if your module is named foo you should have config file foo.auto.tfvars.json. Change your terragrunt modules (terragrunt.hcl) to have these statements:
locals {
moduleconfig = get_env("TGR_CFGDIR")
modulename = basename(get_terragrunt_dir())
}
generate "configuration" {
path = "config.auto.tfvars.json"
if_exists = "overwrite"
disable_signature = true
contents = file("${local.moduleconfig}/${local.modulename}.auto.tfvars.json")
}
And finally call terragrunt cli like this:
TGR_CFGDIR="<configdir>" terragrunt "<somecommand>"
I have the following directory structure
Apps
|--ComponentLibrary
|----package.json
|--MyProject1
|----package.json
|--MyProject2
|----package.json
I want to be able to use components from ComponentLibrary in MyProject1 like:
MyProject1/App.js
import {Button} from 'ComponentLibrary/components/button';
Is there a way I can alias ComponentLibrary in MyProject1? I imagine there's some flag I can add in package.json
Currently I get the following expected error
Modules does not exist in the module map
This is a pretty simple problem, and I have read a number of suggested solutions, but I still can't get puppet apply to import the git::config class. Here is my file setup:
I import the git module via nodes.pp:
#/etc/puppet/manifests/nodes.pp
node default {
}
include git
site.pp imports nodes.pp:
#/etc/puppet/manifests/site.pp
import 'nodes.pp'
The git module is defined as follows:
#/etc/puppet/modules/git/manifests/init.pp
class git {
include git::install
include git::config
}
class git::install{
package {'git': => present }
}
and the config file:
#/etc/puppet/modules/git/manifests/config.pp
define git::config{
[some code here]
}
When I run puppet apply, puppet does not find the git::config class:
sudo puppet apply --modulepath=/etc/puppet/modules /etc/puppet/manifests/site.pp
Error: Could not find class git::config for xxxx on node xxxx.
The original module was puppetlabs-git (same folder structure), but I have recreated the error using the simplified file structure (above).
Update 1
Typo above, the git config.pp and init.pp are in folder /modules/git/manifests and the config.pp file reads 'define git::config'
You cannot call include on git::config. git::config is a defined type, not a class. The syntax to use a defined type is as follows:
git::config { 'the_name_var':
param1 => 'foo',
param2 => 'bar'
}
Hope this helps
Your puppet code structure is wrong. You need move your pp file to manifests folders.
/etc/puppet/modules/git/init.pp
/etc/puppet/modules/git/config.pp
to
/etc/puppet/modules/git/manifests/init.pp
/etc/puppet/modules/git/manifests/config.pp
It seems pretty simple thing, and it works on Vagrant, but I can't make it work on a EC2 server.
When:
puppet apply manifests/init.pp
Error:
Could not find class base for s1.ec2.internal at /var/lib/jenkins/jobs/s1/workspace/manifests/init.pp:1 on node s1.ec2.internal
File ./manifests/init.pp:
include base
File ./manifests/base.pp:
class base {
exec { "apt-get update":
command => "/usr/bin/apt-get update",
timeout => 0
}
package { ["vim", "git", "build-essential"]:
ensure => present,
require => Exec["apt-get update"]
}
}
Puppet v2.7.23
Like Felix stated the class base is being looked for in the modules of your puppet manifests. The directory structure of your modules as follows:
$confdir/
|- manifests
|- init.pp <- The file you reference to when executing puppet apply
|- modules
|- base
|- manifests
|- init.pp <- The file containing your base class
What Felix forgot to mention was that there needs to be another manifests directory within the base module directory.
See also https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html
Usually class base will be found only in a module named base.
Try putting it into modules/base/init.pp instead of manifests/base.pp.
In my case it was a permissions issue - the files were owned by root but I wasn't running puppet with sudo
I have been experimenting with hiera for configuration data. The hiera.yaml file has the following configuration:
---
:backends:
- yaml
:hierarchy:
- "servers/%{hostname}"
- common
but when I run hiera from the command line to test it,
hiera some::var hostname=foo
it does not pick up the configuration from servers/foo/yaml. Adding the -d (debug) option shows that it doesn't even look at that file. Instead, it says something like:
Looking for data source services/foo
Cannot find database /etc/puppet/hiera/services/foo.yaml, skipping
So, two questions:
Why is it not looking in the servers directory?
Why is it looking in a "services" directory? (Note that it looks for things in the services directory even if we remove the "servers/%{::hostname}" line from the hiera.yaml file!)
If by default hiera looks for things in special directories like "services", then where is this documented?
I think the reason may be that a) you are not using the default location for hiera datadir (which is /var/lib/hiera) and b) you have forgotten to specify that datadir within the hiera.yaml (or whatever filename you want your hiera config file to be). That is what a possible solution might be is just adding the following to your hiera config file:
:yaml:
:datadir: /tmp/var-lib-hiera
Check out the following example:
/tmp/var-lib-hiera $ hiera -c hiera.yaml some::var hostname=foo
100
/tmp/var-lib-hiera $ tree
.
├── hiera.yaml
└── servers
└── foo.yaml
/tmp/var-lib-hiera $ head hiera.yaml servers/foo.yaml
==> hiera.yaml <==
---
:backends:
- yaml
:hierarchy:
- "servers/%{hostname}"
- common
:yaml:
:datadir: /tmp/var-lib-hiera
==> servers/foo.yaml <==
some::var: 100
Apparently, the configuration will work if: hiera is run with the -c option to specify the exact location of the configuration file. (A symlink from /etc/hiera.yaml did not work, though that was a suggestion from another forum https://ask.puppetlabs.com/question/3149/where-does-hiera-search-for-data-sources/?answer=3152#post-id-3152)
If you are using puppet you can set the location of the hiera file in e master section of puppet.conf so you don't have to provide it on cmd line.
See: http://docs.puppetlabs.com/references/latest/configuration.html#hieraconfig