Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all 89 articles
Browse latest View live

Cannot retrieve custom facts on some hosts

$
0
0
Hi all, I have a rare anomaly where on some hosts, custom facts do not work. I am on PE 2.7. I get this error during puppet runs: Could not retrieve colo_code: private method `chop' called for nil:NilClass And with all messages leading up to the error: info: Caching certificate for dbx01-sc9.virginam.com info: Retrieving plugin info: Caching certificate_revocation_list for ca info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/puppet_vardir.rb info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/facter_dot_d.rb info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/colo_code.rb info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/root_home.rb Could not retrieve colo_code: private method `chop' called for nil:NilClass Could not retrieve colo_code: private method `chop' called for nil:NilClass info: Caching catalog for dbx01-sc9.virginam.com info: Applying configuration version '1412110455' The custom fact shows up on most nodes, as shown with `facter -p` The configuration is the same on all hosts and the script used for the custom facts, colo_code.rb looks correct. Here is the script: Facter.add("colo_code") do setcode do %x{/bin/hostname}[/(sc9|bgm|sac)\./].chop end end

Upgrading Ruby

$
0
0
I would like to upgrade Ruby from 1.8.7. > 2.1.4. - I can't seem to find any documentation regarding this with its coorelation to puppet. After the upgrade, my system no longer recognizes `service puppetmaster status`. Is there any information on how to upgrade Ruby on a already existing puppetmaster server?

how to compare facts with all other facts in a text file

$
0
0
Hi, I am trying to compare my existing facts using text file. But it is giving me wrong answer. Here is my facts require 'rexml/document' require 'facter/util/file_read' require 'facter' logfile = "/home/weblogic/javacheck.txt" java_count = 0 log = Facter::Util::FileRead.read(logfile) unless log.nil? log.each_line do |line| if line.include?('/java') java_count += 1 val = "#{line}" Facter.add(:isjavaversion) do setcode do if Facter.value(:java_foundversion2_path2) == #{val} true else false end end end end end end Here is my text file 1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/bin/java 1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/jre/bin/java 1.5.0/opt/itm/v6.2.2/JRE/lx8266/bin/java 1.7.0_72/u01/java/jdk1.7.0_72/jre/bin/java 1.7.0_72/u01/java/jdk1.7.0_72/bin/java 1.7.0_65/u01/java/jdk1.7.0_65/jre/bin/java 1.7.0_65/u01/java/jdk1.7.0_65/bin/java java_founfversion2_path fact mactches to the text file. But it is returning false statement. It is not reading line by line when i do using irb statement. it is taking as entire string. "1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/bin/java\n1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/jre/bin/java\n1.5.0/opt/itm/v6.2.2/JRE/lx8266/bin/java\n1.7.0_72/u01/java/jdk1.7.0_72/jre/bin/java\n1.7.0_72/u01/java/jdk1.7.0_72/bin/java\n1.7.0_65/u01/java/jdk1.7.0_65/jre/bin/java\n1.7.0_65/u01/java/jdk1.7.0_65/bin/java\n How to split these lines by line?

could not load open ssl; cannot install

$
0
0
Hi, I have tried to install puppet opensource on 2 offline machines: ubuntu 12.04 and Red Hat 6. I have installed ruby 2.2.0 from tar.gz file and then I installed Facter and Hiera from tar.gz file. Both facter and hiera installed successfully, However When i try to run ruby install.rb on the puppet installation it failed with the following error: ftools not found. Using FileUtils instead.. Could not load openssl; cannot install I hope someone could help because I cant install it in my organization (The installation must occur on offline machines)

current activerecords breaks puppet with storeconfigs

$
0
0
Hi, I'm running puppet 3.7.2 (debian jessie) and want to use storeconfigs in the old activerecords style. I know it's deprecated, but it seems that currently it is also broken: Error: Could not retrieve catalog from remote server: Error 400 on SERVER: undefined method `verify_active_connections!' for ActiveRecord::Base:Class And yes, that method doesn't exist anymore as far as I can tell. I'm using activerecords 4.1.8. What are my options? Thanks, ~David

How to declare a selectable hash class parameter?

$
0
0
Salut, I need a selectable hash parameter in my class definition:
class colors (
  $flavor      = 'myfavorites',
  $nice_colors = $flavor ? {
    'myfavorites' => {
      'red'   => false,
      'green' => true,
      'blue'  => false,
    },
    default => {
      'red'   => true,
      'green' => true,
      'blue'  => true,
    },
  },
) inherits colors::params {
  Class['colors::install'] -> Class['colors::config']
  contain 'colors::install'
  contain 'colors::config'
}
Since hash literals can't be specified in a '?'-selector I need to go around this problem. Later I need to iterate over the hash in a template.
<%- @nice_colors.each do |color, isnice| -%><%- if not isnice %>no<% end %><%= color %><%# -%><%- end -%>
Does anyone have an idea (and when yes, what's your idea?)? Thx a lot.

set "global" variable from custom function

$
0
0
Hi, I have a custom function that performs some complicated processing on a map that i get from a hiera conf. After the processing is done, let us suppose that the result is stored in an array and returned to the calling recipe(in this case a class i defined). Is there a way to make the return array available to other classes/recipes(other than the one that called the custom function that is). If you think my approach is not puppet-complaint please advise on the best way to perform what I am after. Regards

ERB - don't output variable value if current config file has a value?

$
0
0
To clarify the title there is a config file for some application that I have used Puppet to deploy, however the application encrypts certain variables at service startup rather than the plaintext that I am passing in through Puppet. Each time Puppet runs it wants to replace these hashed/encrypted strings. Is there a way to tell Ruby/ERB/Puppet not to output from the `<%= @myVar %>` if there is already a string in that location in the configuration file already present on the server? Hopefully that makes sense.

Custom fact - get disk size?

$
0
0
I have a custom fact that is using the following to obtain the root volume disk size: s = Facter::Core::Execution.exec('df -k | head -n 2 | tail -n 1 | awk \'{print $2}\'').chomp Or: s = Facter::Core::Execution.exec('df -hk /myfolder | tail -n 1 | awk \'{print $1}\'').chomp I then do some arithmetic on `s` and compute a value in Gb. It is not an ideal solution and will cause problems later on. Ideally I'd have a way to interrogate volumes/disks and get the associated attributes rather than executing this shell command. As is explained in the accepted answer here: http://stackoverflow.com/questions/4508692/get-available-diskspace-in-ruby On that note is it possible to use statements such as: require 'sys/filesystem' From within custom facts? If so, how would one go about installing the 'sys/filesystem' library as suggested in that SO thread? All input appreciated.

Puppet/Ruby File.exists?() not working on Windows

$
0
0
Hello community, this the first time I (have to) use ask, but now I seem to be stuck with a rather trivial problem on Windows, checking for an existing file with ruby. May goal is to load a YAML file from disk into a puppet hash. Problem: Ruby `File.exists` does not to be working as expected for me, it is used in the `loadyaml()` function of puppet stdlib. Do debug this, I use the following class with inline template: `inline_template('<% if File.exist?(@version_yml) -%>true<% else -%>false<%end -%>')` Since the file is created in the puppet run, it *should* exist. class debug::fileexists ($destination, $version) { $yml = "#managed by puppet\n---\nversion: ${version}\n" validate_absolute_path($destination) $version_yml = "${destination}/version.yml" # workaround: use inline ruby to test for existing version file notify { 'filepath': message => "YAML- File: ${version_yml}" } -> file { $version_yml: ensure => present, mode => '777', content => $yml, } -> notify { 'inline_template': message => inline_template('<% if File.exist?(@version_yml) -%>true<% else -%>false<%end -%>') } } However, my puppet output looks like this: C:\Program Files\Puppet Labs\Puppet\bin>puppet apply c:\debug.pp Notice: Compiled catalog for wstest02.int.m-box.de in environment production in 0.28 seconds Notice: YAML- File: C:/test/version.yml Notice: /Stage[main]/Debug::Fileexists/Notify[filepath]/message: defined 'message' as 'YAML- File: C:/test/version.yml' Notice: /Stage[main]/Debug::Fileexists/File[C:/test/version.yml]/ensure: created Notice: false Notice: /Stage[main]/Debug::Fileexists/Notify[inline_template]/message: defined 'message' as 'false' Notice: Finished catalog run in 0.19 seconds Sure enough, the file exists: C:\Program Files\Puppet Labs\Puppet\bin>dir C:\test\version.yml Volume in drive C has no label. Volume Serial Number is 0095-8D6F Directory of C:\test 09.07.2015 11:24 34 version.yml 1 File(s) 34 bytes 0 Dir(s) 651.091.238.912 bytes free Running the same code in IRB, works as well: irb(main):001:0> version_yml = 'C:/test/version.yml' => "C:/test/version.yml" irb(main):002:0> File.exists?(version_yml) => true irb(main):003:0> require 'yaml' => true irb(main):004:0> YAML.load(File.open(version_yml)) => {"version"=>1} Versions: C:\Program Files\Puppet Labs\Puppet\bin>facter architecture => x64 dir => C:\Program Files\Puppet Labs\Puppet\facter env_windows_installdir => C:\Program Files\Puppet Labs\Puppet facterversion => 2.3.0 fqdn => wstest02.int.m-box.de hardwaremodel => x64 hostname => wstest02 is_virtual => false kernel => windows kernelmajversion => 6.3 operatingsystem => windows operatingsystemmajrelease => 8 operatingsystemrelease => 8.1 os => {"name"=>"windows", "family"=>"windows", "release"=>{"major"=>"8", "minor"=>"1", "full"=>"8.1"}} osfamily => windows puppetversion => 3.8.1 rubyplatform => x64-mingw32 rubysitedir => C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/site_ruby/2.0.0 rubyversion => 2.0.0 system32 => C:\Windows\system32 virtual => physical

Couldn't start puppet 4.2

$
0
0
Hi There, When I starting puppet 4.2 `service puppetserver start`, following errors appears. `[...] 2015-07-30 16:03:38,817 ERROR [p.t.internal] shutdown-on-error triggered because of exception! java.lang.IllegalStateException: There was a problem adding a JRubyPuppet instance to the pool. [...] Caused by: org.jruby.embed.EvalFailedException: (Error) Cannot determine basic system flavour [...]` I've seen the following know issue but I don't know if is a related problem : [Ruby 1.8 vs Ruby 1.9](https://github.com/puppetlabs/puppet-server/blob/master/documentation/known_issues.markdown). As anyone the same problem or as an idea? P.S.-: Should the puppet client be configured too? Because actually I've only installed and configured the Master server. Regards

issue when upgrading ruby 1.9.3

$
0
0
Hi, I want to upgrade ruby from 1.8.7 to 1.9.3, using rvm install. Upgrading to support "puppetlabs_spec_helper" gem for rspec-test, since this will only support if ruby 1.9.3 present. Getting below error when installing ]# rvm reinstall ruby-1.9.3-p551 ruby-1.9.3-p551 - #removing src/ruby-1.9.3-p551.. ruby-1.9.3-p551 - #removing rubies/ruby-1.9.3-p551.. Searching for binary rubies, this might take some time. No binary rubies available for: redhat/6/x86_64/ruby-1.9.3-p551. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for redhat. Requirements installation successful. Installing Ruby from source to: /usr/local/rvm/rubies/ruby-1.9.3-p551, this may take a while depending on your ruby-1.9.3-p551 - #downloading ruby-1.9.3-p551, this may take a while depending on your connection... ruby-1.9.3-p551 - #extracting ruby-1.9.3-p551 to /usr/local/rvm/src/ruby-1.9.3-p551.... ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/GH-488.patch. ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/1.9.3/CVE-2015-1855-p484.patch. ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/ssl_no_ec2m.patch. ruby-1.9.3-p551 - #configuring............................................. ruby-1.9.3-p551 - #post-configuration.. ruby-1.9.3-p551 - #compiling................................................................... ruby-1.9.3-p551 - #installing........................ ruby-1.9.3-p551 - #making binaries executable.. curl: (28) connect() timed out! There was an error while trying to resolve rubygems version for 'latest'. Halting the installation. I enabled proxy by "export http_proxy" and doing "rvm install 1.9.3" I tried ruby rpm installation as well (downloded ruby 1.9.3 rpm package), but throwing one or the other dependency error. Can someone help me on this I am breaking my head for last two days

Beaker Error: getaddrinfo: Name or service not known

$
0
0
I am writing an acceptance test for my Puppet module using Beaker. My module depends on PuppetDB to get some info. To add PuppetDB dependency, I added `dependency 'puppetlabs/puppetdb'` to my Modulefile and this mod 'puppetlabs/puppetdb', path: 'puppet', git: 'https://github.com/puppetlabs/puppetdb.git' to my Puppetfile. However, when I run my acceptance test, I get `Error: getaddrinfo: Name or service not known` I googled and tried multiple approaches like giving the correct permission to /etc/hosts file, manually running PuppetDB on the VM created by Beaker, but I can't go past this error. It would be great if anyone put me in right direction. Considering I am new to Puppet and Beaker, is it even possible to write an acceptance test for the module that depends on PuppetDB?

Write a basic custom module for puppet

$
0
0
I have some experience handling puppet modules but this time I wrote some code in Ruby that I'd like to port to a custom puppet module. I already have read puppetlabs documentation( puppetforge, Beginner's guide )about writing custom modules but I still don't get a basic idea to build from zero a dummy custom puppet module to test it. Do you know where can I find some practical examples to build a dummy custom puppet module?

Performance improvements without updating to Puppet Server?

$
0
0
It will be some time before our system is ready to move to Puppet Server aka Puppet 4.0. However we would be interested in anything that gets us closer to the performance increase in Puppet Server without large changes. Also would be nice to have the changes isolated to the master and require no agent changes. What are our options?

Under which conditions does @resource exist in a custom provider?

$
0
0
In certains conditions @resource is nil in custom providers. When can I safely use it and how can I get parameters otherwise? Code is there https://github.com/puppet-community/puppet-corosync/blob/develop/lib/puppet/provider/cs_primitive/pcs.rb#L275 Failing travis test is there https://travis-ci.org/puppet-community/puppet-corosync/builds/80850531

Unable to install Puppet server due to dependency error

$
0
0
Hi, When we try to install puppet-server, we received below error message. We already have ruby(ver. 1.9.3) installed in the server but getting dependency error. It would be helpful if anyone can give the solution for this. Thank you. [root@myserver ~]# yum install puppet-server Loaded plugins: security Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package puppet-server.noarch 0:3.8.3-1.el6 will be installed --> Processing Dependency: puppet = 3.8.3-1.el6 for package: puppet-server-3.8.3-1.el6.noarch --> Running transaction check ---> Package puppet.noarch 0:3.8.3-1.el6 will be installed --> Processing Dependency: facter >= 1:1.7.0 for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: ruby >= 1.8.7 for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: hiera >= 1.0.0 for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: ruby >= 1.8 for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: ruby(selinux) for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: /usr/bin/ruby for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: rubygem-json for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: ruby-shadow for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: ruby-augeas for package: puppet-3.8.3-1.el6.noarch --> Running transaction check ---> Package facter.x86_64 1:2.4.4-1.el6 will be installed --> Processing Dependency: ruby >= 1.8.7 for package: 1:facter-2.4.4-1.el6.x86_64 --> Processing Dependency: /usr/bin/ruby for package: 1:facter-2.4.4-1.el6.x86_64 ---> Package hiera.noarch 0:1.3.4-1.el6 will be installed --> Processing Dependency: ruby >= 1.8.5 for package: hiera-1.3.4-1.el6.noarch --> Processing Dependency: /usr/bin/ruby for package: hiera-1.3.4-1.el6.noarch ---> Package puppet.noarch 0:3.8.3-1.el6 will be installed --> Processing Dependency: ruby >= 1.8.7 for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: ruby >= 1.8 for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: ruby(selinux) for package: puppet-3.8.3-1.el6.noarch --> Processing Dependency: /usr/bin/ruby for package: puppet-3.8.3-1.el6.noarch ---> Package ruby-augeas.x86_64 0:0.4.1-3.el6 will be installed --> Processing Dependency: ruby(abi) = 1.8 for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: augeas-libs >= 0.8.0 for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: libaugeas.so.0(AUGEAS_0.10.0)(64bit) for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: libaugeas.so.0(AUGEAS_0.1.0)(64bit) for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: libaugeas.so.0(AUGEAS_0.11.0)(64bit) for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: libaugeas.so.0(AUGEAS_0.8.0)(64bit) for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: libaugeas.so.0(AUGEAS_0.12.0)(64bit) for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: libruby.so.1.8()(64bit) for package: ruby-augeas-0.4.1-3.el6.x86_64 --> Processing Dependency: libaugeas.so.0()(64bit) for package: ruby-augeas-0.4.1-3.el6.x86_64 ---> Package ruby-shadow.x86_64 1:2.2.0-2.el6 will be installed --> Processing Dependency: ruby for package: 1:ruby-shadow-2.2.0-2.el6.x86_64 --> Processing Dependency: libruby.so.1.8()(64bit) for package: 1:ruby-shadow-2.2.0-2.el6.x86_64 ---> Package rubygem-json.x86_64 0:1.5.5-3.el6 will be installed --> Processing Dependency: ruby(abi) = 1.8 for package: rubygem-json-1.5.5-3.el6.x86_64 --> Processing Dependency: rubygems >= 1.3.7 for package: rubygem-json-1.5.5-3.el6.x86_64 --> Processing Dependency: /usr/bin/ruby for package: rubygem-json-1.5.5-3.el6.x86_64 --> Processing Dependency: libruby.so.1.8()(64bit) for package: rubygem-json-1.5.5-3.el6.x86_64 --> Processing Dependency: /usr/bin/ruby for package: 1:facter-2.4.4-1.el6.x86_64 --> Processing Dependency: /usr/bin/ruby for package: rubygem-json-1.5.5-3.el6.x86_64 --> Processing Dependency: /usr/bin/ruby for package: hiera-1.3.4-1.el6.noarch --> Processing Dependency: /usr/bin/ruby for package: puppet-3.8.3-1.el6.noarch --> Finished Dependency Resolution Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: libaugeas.so.0(AUGEAS_0.11.0)(64bit) Error: Package: 1:facter-2.4.4-1.el6.x86_64 (puppetlab-base) Requires: ruby >= 1.8.7 Error: Package: rubygem-json-1.5.5-3.el6.x86_64 (puppetlab-dep) Requires: ruby(abi) = 1.8 Error: Package: 1:ruby-shadow-2.2.0-2.el6.x86_64 (puppetlab-dep) Requires: libruby.so.1.8()(64bit) Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: libaugeas.so.0(AUGEAS_0.12.0)(64bit) Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: libaugeas.so.0(AUGEAS_0.8.0)(64bit) Error: Package: 1:facter-2.4.4-1.el6.x86_64 (puppetlab-base) Requires: /usr/bin/ruby Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: libaugeas.so.0()(64bit) Error: Package: hiera-1.3.4-1.el6.noarch (puppetlab-base) Requires: ruby >= 1.8.5 Error: Package: rubygem-json-1.5.5-3.el6.x86_64 (puppetlab-dep) Requires: libruby.so.1.8()(64bit) Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: augeas-libs >= 0.8.0 Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: libaugeas.so.0(AUGEAS_0.10.0)(64bit) Error: Package: 1:ruby-shadow-2.2.0-2.el6.x86_64 (puppetlab-dep) Requires: ruby Error: Package: hiera-1.3.4-1.el6.noarch (puppetlab-base) Requires: /usr/bin/ruby Error: Package: puppet-3.8.3-1.el6.noarch (puppetlab-base) Requires: ruby >= 1.8.7 Error: Package: puppet-3.8.3-1.el6.noarch (puppetlab-base) Requires: ruby >= 1.8 Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: ruby(abi) = 1.8 Error: Package: puppet-3.8.3-1.el6.noarch (puppetlab-base) Requires: ruby(selinux) Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: libaugeas.so.0(AUGEAS_0.1.0)(64bit) Error: Package: rubygem-json-1.5.5-3.el6.x86_64 (puppetlab-dep) Requires: rubygems >= 1.3.7 Error: Package: rubygem-json-1.5.5-3.el6.x86_64 (puppetlab-dep) Requires: /usr/bin/ruby Error: Package: puppet-3.8.3-1.el6.noarch (puppetlab-base) Requires: /usr/bin/ruby Error: Package: ruby-augeas-0.4.1-3.el6.x86_64 (puppetlab-dep) Requires: libruby.so.1.8()(64bit) You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest

How to list a files and its names in Puppet ( Linux )

$
0
0
We are having multiple unstructured static IpAddress configuration in linux. **Like the below :** ( i ) ifcfg-eth0 ( ii ) ifcfg-eth0:1 ( iii ) ifcfg-eth0:2 ( iv ) ifcfg-eth1 ( v ) ifcfg-eth2:2 ( vi) ifcfg-eth3:5 Each machine, We are going to have some sorts of files ( like the above unstructured way). I would like create new file with new ipaddress. Inorder to do that We need to know the last used file / used filename. I think we could achieve it from the [custom function][1], but not sure. Any help would be much appreciated. [1]: https://docs.puppetlabs.com/guides/custom_functions.html

Writing quotes in values with puppetlabs-inifile

$
0
0
I've been using [puppetlabs-inifile][1] to manage configuration files for various services, and I also want to use it to manage InfluxDB. InfluxDB is written in Go and is strict about the configuration file format - i.e. strings must be quoted, while ints and booleans must not. The problem; puppetlabs-inifile strips out the quotes, but I can't find any code to indicate that this is deliberate. It seems, to my untrained eye, to be incidental. For example, the following ini_setting declaration: ini_setting { "foo_bar": section = 'foo', setting = 'bar', value = '"boz"' } Results in: [foo] bar = boz Same applies when `value => "'boz'"`, and even `value => '\"boz\"'` I figured it was probably due to the way puppet handles strings, so I created a custom provider in my module, which extends ini_setting to append the quotes explicity: Puppet::Type.type(:influxdb_setting).provide( :ini_setting, # set ini_setting as the parent provider :parent => Puppet::Type.type(:ini_setting).provider(:ruby) ) do def value # Add encapsulating quotes for strings if resource[:quote_value] rv = resource[:value].prepend('"') << '"' puts rv return rv else resource[:value] end end def quoted_value resource[:quoted_value] end end The type, influxdb_setting, is a direct copy-paste of [ini_setting.rb](https://github.com/puppetlabs/puppetlabs-inifile/blob/master/lib/puppet/type/ini_setting.rb), with the addition of: newparam(:quote_value, :boolean => true, :parent => Puppet::Parameter::Boolean) do desc 'Quote the value' defaultto :false end Using this type, the puts statement returns the strings as expected, so I believe the stripping is happening on the output side. An obvious solution, would be to use [ini_subsetting](https://github.com/puppetlabs/puppetlabs-inifile#manage-multiple-values-in-a-setting), but there's a snag there too. InfluxDB's modules use two square brackets for the section heading, so I also need the `section_prefix` and `section_suffix` parameters, which are provided by ini_setting but not ini_subsetting. My question is, where puppetlabs-inifile are the quotes being stripped? Having read through the [code](https://github.com/puppetlabs/puppetlabs-inifile/blob/d452e6ca1e8df61cb639d85d5944df465096d886/lib/puppet/util/ini_file.rb#L60-L100) I can't see where it's happening and thus what I need to override. Any advice appreciated! [1]: https://github.com/puppetlabs/puppetlabs-inifile [2]: https://github.com/al4/puppet-influxdb

How to set a ruby variable on erb template

$
0
0
Hello, I'm trying to do set a variable on erb template. I explain with an example. I create a vhost file for apache. I have many server level : dev / int / prd, I set the $server_level on nodes.pp And I want set the vhost IP on the erb template. The IP depends of the level, and the IP is set by facter. Like this : <% if @server_level == "dev" %><% @IP_site=@ipaddress_eth0%><% end %><% if @server_level == "int" %><% @IP_site=@ipaddress_eth1%><% end %><% if @server_level == "prd" %><% @IP_site=@ipaddress_eth2%><% end %> Goal is to use on the erb file the IP_site variable and not do this if statement each time I want to print the IP. But the expression I wrote before is wrong and I'm not à rubyman... Can you help me? Thanks a lot!
Viewing all 89 articles
Browse latest View live


Latest Images