Execs

Creating multiple directories

Srouce

When creating directory structure with a high number of directories and leading zeros, the puppet-lint gives depending on the syntax in the used exec resource some errors.

Goal:

/
- 001
- 002
- 003
- 004
...

Puppet code:

exec {'test':
  command => "for i in {00..99}; do c=000\$i; /bin/mkdir -p /tmp/data/\${c: -2}; done",
  provider => shell,
}

Alternative 2:

exec {'test':
  command => 'for i in {00..99}; do c=000$i; /bin/mkdir -p /tmp/data/${c: -2}; done',
  provider => shell,
}

Since this syntax is rather quite complicated, the workaround here without shooting the linting down is to disable the linting for the specific lines in the code. The linters control statements are of good use here:

exec {'test':
  # lint:ignore:double_quoted_strings
  command => "for i in {00..99}; do c=000\$i; /bin/mkdir -p /tmp/data/\${c: -2}; done",
  # lint:endignore
  provider => shell,
}

or

exec {'test':
  command => "for i in {00..99}; do c=000\$i; /bin/mkdir -p /tmp/data/\${c: -2}; done", # lint:ignore:double_quoted_strings
  provider => shell,
}

Facter

Debugging, strace

Source

On CentOS 7 I was struggeling with an error caused by the lvmconfig module. Somewhere in there was a bug. The problem was finding the module as a source. The provided facts where copied by puppet (pluginsync) on the node and then killed the facter output with a ruby error message. Something like this:

...
Info: Loading facts
Error: Could not retrieve local facts: private method `split' called for nil:NilClass
Error: Failed to apply catalog: Could not retrieve local facts: private method `split' called for nil:NilClass

The problem was to identify which fact in which module caused this error.Running facter in debug mode, just made it worse. The error there pointed to ec2_metadata, but I could not find any custom fact for this in the sources:

$ facter --puppet --debug
Found no suitable resolves of 1 for ec2_metadata
value for ec2_metadata is still nil
private method `split' called for nil:NilClass

Running facter with strace on the other hand, increased the output significantly and gave the hint to the module in question:

$ strace facter -p -d
....

Hiera

Resource dependencies

Source When trying to configure resources in hiera and trying to create them with create_resources, the resource often is not found.

  • Example:
---
profile::user:
  usera:
    ensure: present
  userb:
    ensure: present
    require: User['usera']
class profile (
  $user = ''
) {

  create_resources(user,$user)
}

The key is in the way to reference the dependency in hiera without any apostrophe :

profile::user:
  usera:
    ensure: present
  userb:
    ensure: present
    require: User[usera]

Config

Set config parameters

$ sudo puppet config set interval 700 --section main
$ sudo puppet config set environment test --section agent

Error

Import Loops

Source In a directory environment configuration the autoload-mechanism is differentfrom the configuration environment in versions before directory environments where available.

The entry/start point for puppet is the manifest folder (<environment>/manifests/), not the file site.pp. Therefore all files are imported as one manifest file. Additional imports in the same folder hierarchy level are therefore leading to the import loop error.

Subdirectories still need to be imported in at least one of the manifest files in the manifest root folder.

Error:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not parse for environment production: Import loop detected for /etc/puppet/environments/production/manifests/includedfile.pp at /etc/puppet/environments/production/manifests/site.pp:16 on node the_name_of_your_node

Solution:

Remove the includes from site.pp that point to other files in the same directory level.