I'm trying to work out the correct YAML syntax that would produce the following statement in /etc/httpd/conf/httpd.conf via Hiera):
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" extended
After several attempts, I wind up with one of three results:
LogFormat "%v %h %l %u %t "%r" %s %b "i" "i"" extended
-- or --
LogFormat "%v %h %l %u %t "%r" %s %b "\i" "\i"" extended
-- or --
LogFormat "%v %h %l %u %t "%r" %s %b "%\{Referer\}i" "%\{User-Agent\}i"" extended
(Here is the YAML that produced the above:)
apache::log_formats:
extended: "%v %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\""
-- or --
apache::log_formats:
extended: "%v %h %l %u %t \"%r\" %s %b \"\%{Referer}i\" \"\%{User-Agent}i\""
-- or --
apache::log_formats:
extended: "%v %h %l %u %t \"%r\" %s %b \"%\{Referer\}i\" \"%\{User-Agent\}i\""
I've tried several other combinations in attempts to comment out either the "%" or the "{" from being interpreted somewhere to no avail. Help!!
My environment:
- CentOS 6.6
- Puppet 3.7.0
- puppetlabs-apache 1.7.1
Thank you for any assistance!
Allen
↧
Having trouble converting YAML into LogFormat statement
↧
How to filter hash in puppet manifest?
Hi all, could you please help me. I'm getting dict from hiera in puppet manifest and then trying to filter it and pass in a python script as args.But have an issues.
My hiera:
myclass::server_conf:
'first_serv':
'serv_name': 'testname'
'serv_hostname': 'testhost'
'test_url': 'test@url.com'
'second_serv':
'serv_name': 'testname2'
'serv_hostname': 'testhost2'
'test_url': 'test@url.com2'
My puppet manifest(i'm getting hash from values in hiera):
$server_conf = hiera_hash('myclass::server_conf', {})
As result of this i had $server_conf which contain:
{"first_serv"=>{"serv_name"=>"testname", "serv_hostname"=>"testhost", "test_url"=>"test@url.com"}, "second_serv"=>{"serv_name"=>"serv2", "serv_name"=>"testname2", "serv_hostname"=>"testhost2", "test_url"=>"test@url.com2"}}
Then i want to select from this list only values:
'testname' 'testhost' 'test@url.com' 'testname2' 'testhost2' 'test@url.com2'
I'm trying to do it using map function:
$transforrmed_data = map(server_conf) |$key,$value| { $value }
And getting error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not match |$key,$value| at /manifests/server.pp:26 on node test.node
How can i solve this problem? Also I need to transfer to one more variable `'testname2' 'testhost2' 'test@url.com2'` and pass it to exec command resource. Or somehow run exec command twice with values from `first_serv` and `second_serv`.
Thanks for any help!
↧
↧
"" is not a Hash. It looks to be a String
I have **init.pp** as below:
class mymodule {
include mymodule::users
include mymodule::install
include mymodule::config
include mymodule::service
Class[mymodule::users] -> Class[mymodule::install] -> Class[mymodule::config] -> Class[mymodule::service]
}
I have **install.pp** as below:
class mymodule::install (
$artifacts = undef,
) inherits mymodule::params {
validate_hash($artifacts)
create_resources('different_module::artifact', $artifacts)
}
And I am creating specs for these classes as below:
**init_spec.pp**
require 'spec_helper'
require 'hiera'
describe 'mymodule', :type => :class do
let(:pre_condition) { '
include mymodule::install
include mymodule::users
include mymodule::service
include mymodule::config
' }
it { should contain_class('mymodule') }
end
**install_spec.pp**
require 'spec_helper'
require 'hiera'
describe 'mymodule::install', :type => :class do
let(:pre_condition) {'include different_module'
}
let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
hiera = Hiera.new(:config => 'spec/fixtures/hiera/hiera.yaml')
artifacts = hiera.lookup('mymodule::install::artifacts', nil, nil)
let(:params) { { :artifacts => artifacts } }
it { should contain_class('mymodule::install') }
it { should contain_different_module__artifact('mymodule') }
}
**spec/fixtures/hiera/hiera.yaml**
---
:backends:
- yaml
:yaml:
:datadir: spec/fixtures/hieradata
:hierarchy:
- common
**spec/fixtures/hieradata/common.yaml**
mymodule::install::artifacts:
mymodule:
groupid: 'au.com.org.app'
artifactid: 'mymodule'
version: 'r1.0'
type: 'tgz'
destination: '/tmp/mymodule_r1.0.tar.gz'
timeout: '0'
When I run rspec I am getting the below error:
"" is not a Hash. It looks to be a String at /tmp/mymodule/spec/fixtures/modules/mymodule/manifests/install.pp:6
EDIT:
When I add Alex's fail statement before `validate_hash` all the specs have been failed. Interestingly, I can see the below, only for `should contain_class`, it is empty:
1) mymodule should contain Class[mymodule]
Failure/Error: it { should contain_class('mymodule') }
Puppet::Error:
I got for artifacts at /tmp/mymodule/spec/fixtures/modules/mymodule/manifests/install.pp:6 on node debian-vm.localdomain
And for other specs I can see the value of artifacts as below:
3) mymodule::install should contain Class[mymodule::install]
Failure/Error: it { should contain_class('mymodule::install') }
Puppet::Error:
I got {"mymodule"=>{"groupid"=>"au.com.env.app", "artifactid"=>"mymodule", "version"=>"r4", "type"=>"tgz", "destination"=>"/tmp/mymodule_r49.tar.gz", "timeout"=>"0"}} for artifacts at /tmp/mymodule_r4/spec/fixtures/modules/mymodule_r4/manifests/install.pp:6 on node debian-vm.localdomain
↧
Masterless puppet with hiera dynamic lookup?
Hello,
Here's what I'm trying to achieve:
- masterless puppet for dev,stg,prd environments - on each node have only one version of modules (only for respective environment) - still use hiera for hierarchy and parameter lookups. My puppet.conf looks like this: [main] logdir = /var/log/puppet rundir = /var/run/puppet ssldir = $vardir/ssl environmentpath = $confdir/environments environment = development [agent] classfile = $vardir/classes.txt localconfig = $vardir/localconfig My hiera.yaml: --- :backends: - yaml :yaml: :datadir: /etc/puppet/environments/%{environment}/hieradata :hierarchy: - "%{environment}" - "node/%{::fqdn}" - common :logger: console Environments tree: /etc/puppet/environments/ ├── development │ ├── development.yaml │ ├── hieradata │ │ ├── common.yaml │ │ ├── development.yaml │ │ └── node │ ├── manifests │ │ └── site.pp │ └── modules │ ├── apache ├── production │ ├── hieradata │ └── manifests │ └── site.pp └── staging ├── hieradata │ └── staging.yaml └── manifests └── site.pp I /etc/puppet/environments/development/hieradata/development.yaml I have parameter: apache::private_ip: '10.111.111.111' and command: hiera apache::private_ip environment=development works fine but when I issue: puppet apply /etc/puppet/environments/development/manifests/site.pp --verbose I get: Error: Could not run: Hiera type mismatch: expected Array and got NilClass With debug mode on is still not much helpful: Debug: Runtime environment: ruby_version=1.8.7, puppet_version=3.8.4, run_mode=user Debug: Evicting cache entry for environment 'development' Debug: Caching environment 'development' (ttl = 0 sec) Debug: Evicting cache entry for environment 'development' Debug: Caching environment 'development' (ttl = 0 sec) Debug: Loading external facts from /var/lib/puppet/facts.d Info: Loading facts Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/pe_version.rb Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/facter_dot_d.rb Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/puppet_vardir.rb Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/root_home.rb Info: Loading facts Debug: Loading facts from /etc/puppet/environments/development/modules/puppi/lib/facter/puppi_projects.rb Debug: Loading facts from /etc/puppet/environments/development/modules/puppi/lib/facter/last_run.rb Debug: Loading facts from /etc/puppet/environments/development/modules/puppi/lib/facter/windows_common_appdata.rb Info: Loading facts Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/pe_version.rb Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/puppet_vardir.rb Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/root_home.rb Info: Loading facts Debug: Loading facts from /etc/puppet/modules/puppi/lib/facter/puppi_projects.rb Debug: Loading facts from /etc/puppet/modules/puppi/lib/facter/last_run.rb Debug: Loading facts from /etc/puppet/modules/puppi/lib/facter/windows_common_appdata.rb Info: Loading facts Debug: Loading facts from /var/lib/puppet/lib/facter/pe_version.rb Debug: Loading facts from /var/lib/puppet/lib/facter/facter_dot_d.rb Debug: Loading facts from /var/lib/puppet/lib/facter/puppet_vardir.rb Debug: Loading facts from /var/lib/puppet/lib/facter/root_home.rb Debug: Evicting cache entry for environment 'development' Debug: Caching environment 'development' (ttl = 0 sec) Debug: hiera(): Hiera YAML backend starting Debug: hiera(): Looking up classes in YAML backend Debug: hiera(): Looking for data source development Debug: hiera(): Found classes in development Error: Could not run: Hiera type mismatch: expected Array and got NilClass Puppet version 3.8.4 and hiera 1.3.4 Any suggestions on what could be wrong here, greatly appreciated. Thank you
Here's what I'm trying to achieve:
- masterless puppet for dev,stg,prd environments - on each node have only one version of modules (only for respective environment) - still use hiera for hierarchy and parameter lookups. My puppet.conf looks like this: [main] logdir = /var/log/puppet rundir = /var/run/puppet ssldir = $vardir/ssl environmentpath = $confdir/environments environment = development [agent] classfile = $vardir/classes.txt localconfig = $vardir/localconfig My hiera.yaml: --- :backends: - yaml :yaml: :datadir: /etc/puppet/environments/%{environment}/hieradata :hierarchy: - "%{environment}" - "node/%{::fqdn}" - common :logger: console Environments tree: /etc/puppet/environments/ ├── development │ ├── development.yaml │ ├── hieradata │ │ ├── common.yaml │ │ ├── development.yaml │ │ └── node │ ├── manifests │ │ └── site.pp │ └── modules │ ├── apache ├── production │ ├── hieradata │ └── manifests │ └── site.pp └── staging ├── hieradata │ └── staging.yaml └── manifests └── site.pp I /etc/puppet/environments/development/hieradata/development.yaml I have parameter: apache::private_ip: '10.111.111.111' and command: hiera apache::private_ip environment=development works fine but when I issue: puppet apply /etc/puppet/environments/development/manifests/site.pp --verbose I get: Error: Could not run: Hiera type mismatch: expected Array and got NilClass With debug mode on is still not much helpful: Debug: Runtime environment: ruby_version=1.8.7, puppet_version=3.8.4, run_mode=user Debug: Evicting cache entry for environment 'development' Debug: Caching environment 'development' (ttl = 0 sec) Debug: Evicting cache entry for environment 'development' Debug: Caching environment 'development' (ttl = 0 sec) Debug: Loading external facts from /var/lib/puppet/facts.d Info: Loading facts Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/pe_version.rb Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/facter_dot_d.rb Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/puppet_vardir.rb Debug: Loading facts from /etc/puppet/environments/development/modules/stdlib/lib/facter/root_home.rb Info: Loading facts Debug: Loading facts from /etc/puppet/environments/development/modules/puppi/lib/facter/puppi_projects.rb Debug: Loading facts from /etc/puppet/environments/development/modules/puppi/lib/facter/last_run.rb Debug: Loading facts from /etc/puppet/environments/development/modules/puppi/lib/facter/windows_common_appdata.rb Info: Loading facts Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/pe_version.rb Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/puppet_vardir.rb Debug: Loading facts from /etc/puppet/modules/stdlib/lib/facter/root_home.rb Info: Loading facts Debug: Loading facts from /etc/puppet/modules/puppi/lib/facter/puppi_projects.rb Debug: Loading facts from /etc/puppet/modules/puppi/lib/facter/last_run.rb Debug: Loading facts from /etc/puppet/modules/puppi/lib/facter/windows_common_appdata.rb Info: Loading facts Debug: Loading facts from /var/lib/puppet/lib/facter/pe_version.rb Debug: Loading facts from /var/lib/puppet/lib/facter/facter_dot_d.rb Debug: Loading facts from /var/lib/puppet/lib/facter/puppet_vardir.rb Debug: Loading facts from /var/lib/puppet/lib/facter/root_home.rb Debug: Evicting cache entry for environment 'development' Debug: Caching environment 'development' (ttl = 0 sec) Debug: hiera(): Hiera YAML backend starting Debug: hiera(): Looking up classes in YAML backend Debug: hiera(): Looking for data source development Debug: hiera(): Found classes in development Error: Could not run: Hiera type mismatch: expected Array and got NilClass Puppet version 3.8.4 and hiera 1.3.4 Any suggestions on what could be wrong here, greatly appreciated. Thank you
↧
%{calling_class} doesn't seem to work in hierarchy
Trying to do this in my hiera.yaml:
---
:backends:
- yaml
:hierarchy:
- "nodes/%{::fqdn}"
- "roles/%{calling_class}"
- common The "nodes" entry works if I name a file to match the fqdn (in my test, I am pulling NTP server settings from Hiera). I can't get the data at the roles level to work. Filenames are matching the class::subclass name (in this case, roles::myrole.yaml). The colon is a valid character in Unix for filenames, but it is a special character and needs to be escaped with a \ when referenced on the command line. Not sure if that's an issue or not.
:backends:
- yaml
:hierarchy:
- "nodes/%{::fqdn}"
- "roles/%{calling_class}"
- common The "nodes" entry works if I name a file to match the fqdn (in my test, I am pulling NTP server settings from Hiera). I can't get the data at the roles level to work. Filenames are matching the class::subclass name (in this case, roles::myrole.yaml). The colon is a valid character in Unix for filenames, but it is a special character and needs to be escaped with a \ when referenced on the command line. Not sure if that's an issue or not.
↧
↧
How to manage user accounts?
I'd like to manage user's accounts with puppet, however I didn't find any suitable module for this. I don't want to use LDAP or any sort of centralized authentication. Puppet should ensure that few admin accounts will be present at all servers. I don't care about `uid` or `gid` for user accounts, important is adding ssh key to authorized keys and adding user to some groups `sudo`, etc.
The best way would be using hiera for this, so that I can easily decide which users will be at which group of servers. What's the best practice for this?
↧
hiera dynamic lookup with external facts
It might be the day or the unstable caffeine levels, but this one is bugging me for more than a day now so I decided to ask here.
The set up is simple:
- Puppet 4.3 with hiera
- puppetserver = test node
- hiera.yaml: https://gist.github.com/kreczko/3cfd094dd9e50b29f82f#file-hiera-yaml
In datadir:
- nodes/puppetserver.yaml: https://gist.github.com/kreczko/3cfd094dd9e50b29f82f#file-puppetserver-yaml
- groups/service.yaml: https://gist.github.com/kreczko/3cfd094dd9e50b29f82f#file-service-yaml
- common.yaml:https://gist.github.com/kreczko/3cfd094dd9e50b29f82f#file-common-yaml
- site class: https://gist.github.com/kreczko/3cfd094dd9e50b29f82f#file-init-pp
In the first iteration of 'puppet agent -t' my site class creates an external fact based on the information in "nodes/%{::fqdn}". This works.
In the second iteration I expect hiera to load values from 'groups/service.yaml' and printout 'message' (also defined in the site class). However, when that happens I see the value from common.yaml. Clearly hiera did not its job.
It becomes more confusing if instead I try 'puppet apply -e "notice hiera('message')" which prints correctly the value from groups/service.yaml.
So the fact itself works, but hiera does not make any decisions on it. From https://docs.puppetlabs.com/hiera/3.0/hierarchy.html and https://docs.puppetlabs.com/hiera/3.0/variables.html I would have expected this to work.
What am I doing wrong?
↧
How to create directory before mount in hieradata
Hello,
I'm a bit of a puppet noob... From a yaml in hieradata I know how to both create a directory & to create a mount. However, I'm unsure how to force the ordering of these from within a yaml.
The only solution I could come up with is to create a module I called ramdisk just to order these properly. It does what I want... But what if I want to create a second directory/mount? I don't want to create a new module. Can someone please point me to documentation that will help me learn how to make this more generic so I can pass the arguments required to it.
Here's what I have...
class ramdisk {
file { '/local/common/ramcache':
ensure => 'directory',
owner => 'nobody',
group => 'nobody',
mode => '0750',
before => Mount['/local/common/ramcache'],
} ->
mount { '/local/common/ramcache':
ensure => 'mounted',
atboot => 'true',
device => 'none',
fstype => 'tmpfs',
options => 'nodev,nosuid,noexec,nodiratime,size=10M',
dump => '0',
pass => '0',
require => File['/local/common/ramcache'],
}
}
↧
Razor, hooks and hostnames
Hi,
I am currently dealing with the problem that I need to assign hostnames within razor to a node before it is installed. This is supposed to make sure the host gets the right hostname and puppet certificate from the start.
I was thinking about a way to provide razor dynamically with a hostname using hooks. The hostname pattern provided by razor seems to be hard to set to individual hostnames.
The idea is as follows:
1. A node boots up and registers at Razor.
2. A hook (either "node-booted" or "node-registered" is triggered.
3. As far as I understand hooks until now I could write a script, run a command, alter the json hash I got from razor and return a new hash with an update hostname.
For this purpose I set up an hiera instance on the razor node and will update the datadir using puppet. Then - using whatever key i want - I could assign a hostname to a specific MAC, serialnumber or anything provided by the razor facts.
The advantage I see is that I can already setup a number of hosts before they are installed or powered on and razor would get the hostnames for the installation on the fly. I try to minimize the number of manual actions in razor and keep it in an environment where people are already are used to (like hiera in puppet).
My Question: Is this the way to go or is there an easier way of achiving the goal of having the hostname defined in razor before a node actually shows up?
↧
↧
sub sub folders in hieradata
Hey comm,
I'm using Puppet 4 Open Source.
Being boggled about the following.
I simply would like to have subfolders in my hiera datadir like the following.
`/hieradata/osmajrel/CentOS/7.yaml`.
So that I can make an array of packages and have a specific package installed on CentOS 7 (but **not** on Debian 7 for example)
I'm trying to construct my hiera.yaml `:hierarchy:` with different variables from facter like: "`osmajrel/%{::os.name}/%{::os.release.major}`".
**I tried the following in my `hiera.yaml` `:hierarchy:` to no avail:**
- `"osmajrel/%{::os.name}%{::os.release.major}"` (file containing `base_package` array in `/hieradata/osmajrel/CentOS7.yaml`)
- `"osmajrel/%{::os.name}%-{::os.release.major}"` (file containing `base_package` array in `/hieradata/osmajrel/CentOS-7.yaml`)
- `"osmajrel/%{::os.name}%/{::os.release.major}"` (file containing `base_package` array in `/hieradata/osmajrel/CentOS/7.yaml`)
**It works only if my `hiera.yaml` `:hierarchy:` contains:**
- `"osname/%{::os.name}"` (file containing `base_package` array in `/hieradata/osname/CentOS.yaml`)
- `"osmajrel/%{::os.release.major}"` (file containing `base_package` array in `/hieradata/osmajrel/7.yaml`)
I've got a notify in my packages class to show me which packages would be installed by the agent.
Any idea why merging variables don't seem to work in hiera.yaml?
↧
Hiera calling a parameter set in a module
I am wondering if it is possible or if there is a better way for having a yaml file used by Hiera to have dymanic configuration
My current hiera config is as follows.
:backends:
- yaml
:hierarchy:
- "node/%{::clientcert}"
- "role/%{::dec_role}"
- "dc/%{::dec_dc}"
- common
- firewall
For a role, I want to create an autofs resource however, I also want to pass in a specific parameter.
Yaml file for role is as follows.
autofs::mounts:
icedrop:
mount: /-
mapfile: /etc/autofs.d/auto.ice
mapcontents: '/srv/ice -fstype=cifs,noperm,credentials=/etc/autofs.d/cred/ice_flat_files %{::ice::params::ice_server}/ICE_Flat_Files'
options: --timeout=600
order: 4
Note that I have tired to pass in a parameter I already have set in ice::params::ice_server
However, nothing gets passed in, so it means this is a null value I assume at the moment.
So my question is, can one pass a parameter into Hiera like you would with a normal class or module or can Hiera call this type of parameter.
I could create node yaml file and have this set statically but would prefer to have the one role yaml file and have this working dynamically for all my servers.
Hope I am clear and thanks.
EDIT: To add....
The parameter ice::params::ice_server can be found in a module I have written.
Note $env is a fact we have to determine the environment.
class ice::params::ice_server {
if $env == 'tst' {
$ice_server = 'testserver03'
}
elsif $env == 'prd' {
$ice_server = 'prodserver04'
}
}
Setting the parameter is not an issue and calling itin side other modules is OK, I have done that many times before, but calling it in Heira is not something I have done before.
Looking at the puppet documentation the syntax is supposed to be %{::ice::params::ice_server} however in my yaml file this doesn't return anything. I'm thinking do I need to inherit it somehow or perhaps the scope is wrong?
Hope this makes it clearer.
↧
setting a function as value via hiera
Hi,
I'm currently using the puppet/apache module to manage apache. I have lot's of servers with large blocks of rewrite rules, but those rewrite rules are most times the same, so I want to save them to a seperate file, read that file and add it as a custom fragment to the apache configuration. This works like a charm with puppet code.
apache::vhost { 'xyz.com':
port => '80',
docroot => '/var/www',
custom_fragment => file('role/apache/rules.conf'),
}
but I want to give all virtualhost configuration to hiera and use create_resources to build the vhost configurations. Like this:
apache::vhosts:
xyz.com:
port: '80'
docroot: '/var/www'
custom_fragment: file('role/apache/rules.conf')
this is adding only the text "file('role/apache/rules.conf') to the apache configuration it is not executing the function.
Is there any way to achieve this.
Thank you in advance.
↧
How to set parameters with hiera for a class included in default.pp
setup:
- no puppetmaster
- puppet version 4.3.1
- hiera 1.3.0
currently the default.pp looks like that:
node default {
class { 'ntp': servers => [ 'ntp.ubuntu.com' ] }
}
class { 'apt':
purge_sources_list => true,
purge_sources_list_d => true,
purge_preferences_d => true,
}
hiera_include('roles', [])
hiera_include('sites', [])
hiera.yaml looks like that:
---
:backends:
- yaml
:hierarchy:
- "%{::clientcert}"
- "%{::environment}"
- "%{::domain}"
- "virtual_%{::is_virtual}"
- common
:yaml:
:datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata"
vagrant.yaml
---
roles:
- roles::nginx
- roles::java8
apt::sources:
"openjdk-8":
location: "http://ppa.launchpad.net/openjdk-r/ppa/ubuntu"
release: trusty
repos: main
include_src: false
include_deb: true
key: 'DA1A4A13543B466853BAF164EB9B1D8886F44E2A'
everything works like charm but now i would like to remove the three parameters from the apt class and setting them with hiera. `apt::sources:` are correclty looked up via hiera but if i add `apt:` it does nothing
adding this to my hiera file does not help:
apt::
purge_sources_list: false
purge_sources_list_d: false
purge_preferences_d: false
also tried `apt::init:` as key
it it possible to set the parameter via hiera without using ``hiera_include('classes')`?
↧
↧
More hiera examples
Hi all!
I'm use puppet 4.* on Centos 7 and i want to use hiera with it all.
Suppose i have 1 puppet master host and 1 node test1.
On master i have:
#/etc/puppetlabs/code/hiera.yaml
---
:backends:
- yaml
- json
:yaml:
:datadir: "/etc/puppetlabs/code/hiera/%{::environment}"
:json:
:datadir: "/etc/puppetlabs/code/hiera/%{::environment}"
:hierarchy:
- "nodes/%{::fqdn}"
- "common"
# /etc/puppetlabs/code/hiera/production/nodes/test1.yaml
---
her::parameter_one: "This node is special, so we're overriding the common configuration that the other nodes use."
classes:
- her
#/etc/puppetlabs/code/environments/production/manifests/classes/her/her.pp
class her ($parameter_one = "default text") {
file {'/tmp/her':
ensure => file,
content => $parameter_one,
}
}
And on test1 i run "puppet agent --debug --no-daemonize --onetime"
**Question**: How i can run /etc/puppetlabs/code/environments/production/manifests/classes/her/her.pp with "non default" parameters with hiera?
Some server info:
# uname -a
Linux pm2-chel1.is74.ru 3.10.0-327.10.1.el7.x86_64 #1 SMP Tue Feb 16 17:03:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
# hiera --version
1.3.4
# puppet master --version
4.3.2
# rpm -qa | grep hiera
hiera-1.3.4-5.el7.noarch
# rpm -qa | grep pupp
puppetlabs-release-pc1-1.0.0-1.el7.noarch
puppetdb-termini-3.2.4-1.el7.noarch
puppet-agent-1.3.5-1.el7.x86_64
puppetdb-3.2.4-1.el7.noarch
puppetserver-2.2.1-1.el7.noarch
# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
↧
hiera host-network-information
Hello all!
I trying to figure out how to put my host network information under hiera (using puppet4 opensource with no enc)
Maybe I got this all wrong but this what I was thinking:
Base.pp
profiles::base
include profiles::network
Network.pp # contains my logic to check if it's static or bonding network interface. Calls razoredge network module to actually do the work.
class profiles::network {
If hiera(profiles::network::network_info::type) == bonding { #based on fqdn hiera lookup
network::bond::static { ‘bond0’:
ensure =>‘up’,
ipaddress =>“profiles::network::network_info::ipadress”
else
network::if::static
ensure =>‘up’
ipadress =>“profiles::network::network_info::ipadress”
}
host1.toto.com.yaml #host network information based on fqdn hiera declaration
profiles::network::network_info
type: bonding
ipadress: 10.10.10.10
gateway: 10.10.10.1
routes:
- 10.10.10.2
- 10.10.10.3
I know my code is all wrong but anybody using hiera for host-network-information? Or if it's really bad practice to do so.
Thanks!
Eric
↧
hiera command line fetch particular value
I have data in hiera like below,
nodes:
- hostname: lb01.example.com
ipaddress: 192.168.22.21
- hostname: lb02.example.com
ipaddress: 192.168.22.28
Is it possible to get the IP Address of node lb01.example.com through hiera command line?
↧
Is it possible to update/ write new configuration in hiera_hash with facter or puppet code?
I would like to update and maintain my configurations in `hiera_hash` files. Already, The `Hiera_Hash` file holds some predefined values. Based on users input I would like to add/ update the new configurations in the `hiera_hash` file. To do that, I am trying to write it in Factor level and puppet code level. But No idea whether it will work or not.
Guys, Please let me know Whether my scenario is possible / not.
Any help would be much appreciated !!!
↧
↧
Can I use of multiple datadir for hiera?
I want to make use of multiple hiera datadir, so I configured my hiera.yaml file to look like this:
$ cat /etc/puppetlabs/code/hiera.yaml
---
:backends:
- yaml
:hierarchy:
- "%{::role}"
- common
:yaml:
:datadir:
- "/etc/puppetlabs/code/environments/%{::environment}/hieradata"
- "/etc/puppetlabs/code/hieradata/company_wide_hiera_data"
Notice that for 'datadir' I have specified an array. That's because some of my hieredata isn't specific to a particular environment, instead they are general across the whole company.
When I do a puppet run, I get:
# puppet agent -t
Notice: Local environment: 'production' doesn't match server specified node environment 'castle_production', switching agent to 'castle_production'.
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Lookup of key 'profiles::web_server::sampledata' failed: DataBinding 'hiera': datadir for yaml cannot be an array at /etc/puppetlabs/code/environments/castle_production/site/roles/manifests/web_server_ng.pp:47:3 on node i-77690cff
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
This error message indicates that datadir for yaml cannot be an array.
Is there another way to get round this issue?
↧
can't able to pass a variable with same name in different manifest in puppet 2016.1.1?
In previous i used puppet 2015.v.3.1, in that i pass a variable from one class to another by the same name.
Eg:
In Hiera,
currentgen::prodequ_backup_path: 'C:\Backup'
I got a hiera value to profiles::currentgen
class profiles::currentgen
($prodequ_backup_loc = hiera ('currentgen::prodequ_backup_path')
{
notify {"test":
message=>"$prodequ_backup_loc",
}
}
then i get this $prodequ_backup_loc to my params.pp file
Eg:
class currentgen::currentgen_parms
($prodequ_backup_loc = $prodequ_backup_loc)
inherits profiles::currentgen{
notify {"1test":
message=>"this is $prodequ_backup_loc",
}
}
When i call currentgen::currentgen_parms in site.pp, it notifies whatever in code.
but now i migrate my puppet version to 2016.1.1 it gives error like below
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, default expression for $prodequ_backup_loc tries to illegally access not yet evaluated $prodequ_backup_loc at /etc/puppetlabs/code/environments/production/manifests/site.pp:73:2 on node node_name.
if i change the name of variable mean it works. is this error caused by https://docs.puppet.com/pe/latest/code_mgr_custom.html
↧
Chocolatey/Nuget/Hiera
Hi,
We are planning on using ProGet, using different feeds containing certain packages for different departmental groups. We will be using Chocolatey with Puppet. We are using Hiera, so we will be setting the package url there.
We are trying to figure out the best way to configure Hiera to reflect multiple Chocolatey sources.
For example:
A Windows server needs to have all of the applications we have decided it should get as its base software.
All packages for the base software are under the feed http://servername:81/nuget/BASE' (app1, app2, app3). In this case, Hiera would reflect the http://servername:81/nuget/BASE as the Chocolatey package url source.
We then want to apply software from Puppet based upon the server's role (to simplify, I will say MSOffice)
All packages for the Office role are under the feed http://servername:81/nuget/MSOffice' (app1, app2, app3). Obviously this is a different source than the one above.
Hiera knows that packages can be found under feeds at this url: 'http://servername:81/nuget/' , but how would we use Hiera to have multiple sources for Chocolatey packages? Chocolatey does allow multiple sources for searching. For instance, here is an example from the Chocolatey documentation, where multiple sources can be utilized:
package { 'notepadplusplus':
ensure => '6.7.5',
provider => 'chocolatey',
source => 'C:\local\folder\packages;https://chocolatey.org/api/v2/',
}
Can someone show me ways to use Hiera to give Chocolatey multiple sources to find a package? I realize we can put everything under one feed, but that is not our preferred solution.
Thanks in advance for any assistance!
↧