Ask Your Question
0

Puppet 4 agent still "Using configured environment 'production'" even though ENC specifies differently.

asked 2016-01-05 10:39:49 -0500

masterdam79 gravatar image

updated 2016-01-07 17:45:27 -0500

Hey Comm,

Would be gratefull if someone could help me out with this one.

Aim is to assign an environment to a node through an ENC script, disregarding any optional agent-side configurations.

I have my node/environment declarations in /etc/puppetlabs/code/nodes/ as declared as YAML datadir in /etc/puppetlabs/code/hiera-enc.yaml:

---
:backends:
- yaml
:hierarchy:
- "%{::fqdn}"
- "default"
:yaml:
:datadir: /etc/puppetlabs/code/nodes

My executable ENC (bash) script in /etc/puppetlabs/code/enc as follows:

#!/bin/bash

# Nice little fail function
fail () {
   echo '--- { }'
   exit
}

# Get params
NODE=$1

# Get environment from hiera fed by YAML
ENV=$(hiera environment ::fqdn=${NODE} -y /etc/puppetlabs/code/nodes/${NODE}.yaml --config /etc/puppetlabs/code/hiera-enc.yaml)

# If environment variable exists and is not 'nil'
if [[ "${ENV}" != "nil" && -n ${ENV} ]]
then
   # Echo YAML output
   echo "---"
   echo "environment: ${ENV}"
else
   # Call fail function
   fail
fi

And when I run it:

root@puppet:/etc/puppetlabs/code# ./enc test.domain.tld
---
environment: domain-ext

It returns my environment which I've declared in my node/environment declaration in /etc/puppetlabs/code/nodes/test.domain.tld.yaml:

---
environment: 'domain-ext'

However, when I test my puppet agent:

root@test:~# puppet agent -t
Info: Using configured environment 'production'

I would've expected:

root@test:~# puppet agent -t
Notice: Local environment: 'production' doesn't match server specified node environment 'domain-ext', switching agent to 'domain-ext'.

My agent is installed on Ubuntu 14.04 using the https://apt.puppetlabs.com/puppetlabs... repository, only adding server = puppet.domain.tld to /etc/puppetlabs/puppet/puppet.conf and it tries to apply the production environment without errors, cert signed:

Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for test.domain.tld
Info: Applying configuration version '1452011639'
Notice: Applied catalog in 0.02 seconds

The production environment doesn't have any rules set out.

On the puppet4 server I added in my /etc/puppetlabs/puppet/puppet.conf:

node_terminus = exec
external_nodes = /etc/puppetlabs/code/enc

Thanks in advance!

Richard

edit retag flag offensive close merge delete

Comments

Got a little further as environments apparantly can't have hyphens in them: Got the following error when I declared the environment in the agent's puppet.conf: The environment must be purely alphanumeric, not 'domain-ext' So I renamed the environment to domainext, problem still not solved though.

masterdam79 gravatar imagemasterdam79 ( 2016-01-05 14:25:26 -0500 )edit

Also tried to run my enc script as the puppet user, which returned the same proper YAML output as described above.

masterdam79 gravatar imagemasterdam79 ( 2016-01-05 15:41:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-01-07 14:56:44 -0500

masterdam79 gravatar image

updated 2016-01-07 14:57:58 -0500

Found my own answer :-)

While studying the /var/log/puppetserver/puppetserver.log I found the following error:

2016-01-07 21:33:59,120 WARN  [qtp1385390618-62] [c.p.p.ExecutionStubImpl] Executed an external process which logged to STDERR: /etc/puppetlabs/code/enc: line 13: hiera: command not found

So my ENC script should be:

#!/bin/bash

# Nice little fail function
fail () {
   echo '--- { }'
   exit
}

# Get params
NODE=$1

# Get environment from hiera fed by YAML
ENV=$(/opt/puppetlabs/bin/hiera environment ::fqdn=${NODE} -y /etc/puppetlabs/code/nodes/${NODE}.yaml --config /etc/puppetlabs/code/hiera-enc.yaml)

# If environment variable exists and is not 'nil'
if [[ "${ENV}" != "nil" && -n ${ENV} ]]
then
   # Echo YAML output
   echo "---"
   echo "environment: ${ENV}"
else
   # Call fail function
   fail
fi

Obviously pointing hiera to /opt/puppetlabs/bin/hiera did the trick..

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-01-05 10:39:49 -0500

Seen: 675 times

Last updated: Jan 07 '16