public
Last active

Puppet Module : No Code In Data ~ using Hiera with multiple backends

  • Download Gist
$conf_dir hiera.yaml
YAML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
:backends:
- http
- redis
- yaml
- json
 
:http:
:host: testnode.testenv.abk
:port: 5984
:output: json
:failure: graceful
:paths:
- /config/%{::hostname}.json
- /config/%{::fqdn}.json
- /config/%{::environment}.json
- /config/%{::operatingsystem}.json
- /config/common.json
 
:redis:
:password: my_redis_password
 
:yaml:
:datadir: '/etc/puppet/hieradata/yaml'
 
:json:
:datadir: '/etc/puppet/hieradata/json'
 
:hierarchy:
- %{::hostname}
- %{::fqdn}
- %{::environment}
- %{::operatingsystem}
- common
 
:logger: console
etc puppet hieradata json common.json
JSON
1 2 3 4
{
"message": "It's better to use PuppetDB.",
"this_file": "/etc/puppet/hieradata/json/common.json"
}
etc puppet hieradata yaml CentOS.yaml
YAML
1 2 3
---
public_data : "# created on CentOS"
this_file : "/etc/puppet/hieradata/yaml/CentOS.yaml"
etc puppet hieradata yaml common.yaml
YAML
1 2 3 4
---
public_file : "/tmp/notice"
public_data : "# created on any node"
this_file : "/etc/puppet/hieradata/yaml/common.yaml"
prepare_redis.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12
sed -i 's/^requirepass\s*\S*//g' /etc/redis.conf
 
REDIS_PASSWORD='my_redis_password'
echo "requirepass $REDIS_PASSWORD" >> /etc/redis.conf
 
/sbin/service redis restart
 
redis-cli -a $REDIS_PASSWORD <<'EOF'
set common:secret_file /etc/local.keys
set production:secret_file /etc/global.keys
KEYS *
EOF
testnode.testenv.abk config mynode.json
JSON
1 2 3 4
{
"secret_data": "all the secret keys",
"this_file": "http://testnode.testenv.abk/config/mynode.json"
}
use_hiera.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
gem install hiera hiera-http hiera-puppet hiera-redis
 
cat > site.pp << EOF
\$public_file = hiera('public_file','/tmp/abc')
 
file{
\$public_file:
content => hiera('public_data','a2z'),
ensure => present,
}
 
\$secret_file = hiera('secret_file','/tmp/cba')
 
file{
\$secret_file:
content => hiera('secret_data','z2a'),
ensure => present,
}
 
\$msg = hiera('message', '')
notice(\$msg)
EOF
 
puppet apply --environment=testnode site.pp

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.