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

Ruby code separate from Facter facts.

$
0
0
I saw that when working with custom Types/Providers, it is recommended to put your custom ruby code in a puppet_x directory as to prevent overlapping with code in the puppet namespace. However, when trying to apply the same principal to facter facts, it does not appear that they have access to the puppet_x lib directory when they are syncronized to the agent machine! I was looking at how [rtyler-jenkins](https://forge.puppet.com/rtyler/jenkins) module does the separation. Is my only option to add a folder namespaced under the puppet folder (in the jenkins example, lib/puppet/jenkins/facts)? Are there any guides on getting started writing tests for your broken out ruby code? I'm still new to ruby, and ran into some issues moving beyond my regular rspec-puppet based tests. Thanks in advance!

Provider autoload and gems

$
0
0
Hi! We currently run puppet 3.7 or 3.8 depending on the server. About a couple of years ago we implemented a provider for managing KVM Virtual Machines. The provider has been implemented using the gem ruby-libvirt. Lately some of our puppets are refusing to run with the error: **Error: Could not autoload puppet/provider/libvirtnetwork/libvirt: cannot load such file -- libvirt** due to the: **require 'libvirt'** The module itself ensures that the GEM is installed before the resources are managed. which normally works fine. This error is been triggered by *some* of the puppets that do not instantiate this resource. Others are totally fine. It is unclear to me what makes *some* of the puppets fail, i.e. I have puppets v 3.7 where it works and others in 3.7 where it fails. The libvirt gem is only installed if they use this module. So, all puppets currently working do not have the gem installed. I have reviewed Puppet documentation for Provider development and it does not mention about the usage of GEMS I have looked many provider examples, and most seem to call OS commands. Any idea what could be going on? Also, is there any guide / best practice for implementing providers that depend on Ruby bindings?

Strange invalid value for Integer error

$
0
0
Hi Guys, I got the following msg: Error while evaluating a Function Call, Failed to parse template nrpe/etc/nagios/nrpe.cfg.erb: Filepath: org/jruby/RubyString.java Line: 1228 Detail: invalid value for Integer: "\n" at /etc/puppetlabs/code/environments/prod/modules/nrpe/manifests/classes/configuration.pp:15:15 on node but the .erb file is only 262 lines long, so I assume for '1228', its talking about a jruby file?
The code is currently working on a 3.2 server, this is running against a v4 (2.4) server. The only ruby style code in the .erb is allowed_hosts=<% @env['icinga_servers'].each do |icinga_server| -%><% ipInt = Socket.gethostbyname(icinga_server)[3] %><%= "%d.%d.%d.%d," % [ipInt[0], ipInt[1], ipInt[2], ipInt[3]] %><% end %> but as I know nothing of Java or Ruby, I'm stuck ;) Cheers
Chris

set/lookup mysql ruby array puppet v4

$
0
0
Hi, Got this Error Msg /etc/puppetlabs/code/environments/prod/modules/odbc/templates/etc/odbc.ini.erb Line: 69 Detail: undefined method `at' for nil:NilClass at /etc/puppetlabs/code/environments/prod/modules/odbc/manifests/classes/configuration.pp:4:14 on node Relevant .erb file line SERVER = <%= @mysql['jdbc_nodes_write'].at(0) %> json file "mysql" : { "jdbc_nodes_read" : [ "mysql101.x.com" ], "jdbc_nodes_write" : [ "mysql-clusterdb101.x.com", "mysql-clusterdb102.x.com", "mysql-clusterdb103.x.com" ], Any suggestions ?
Thx,
Chris

Common code inclusion

$
0
0
What's the best approach to include code needed at multiple places? I hardly wanna copy 400 lines of code across a dozen files. I've got a basis defined type `my_class::a`. I've got several other defined types `my_class::b`, `my_class:c`, `my_class::d`. `b`,`c` and `d` share all the same parameters of `a`. Their implementation differs by some values. `b`, `c` and `d` all have additional parameters. define my_class::a ( # COMMON PARAMETER LIST ) { $t = 'a' $x = 42 # IMPLEMENTATION depending on $t and $x (and parameters, of course) }   define my_class::b ( #INCLUDE COMMON PARAMETERS here # additional parameters here ) { $t = 'abc' $x = 43 #INCLUDE COMMON THINGS IMPLEMENTATION # … # some additional things with the additional params (and common parameters) } Ideally the inclusion shall be automatically triggered before/while/during catalog compilation. Having to mind to trigger the common code inclusion each time something in it changed, is already bad. PS: No [splat](https://docs.puppet.com/puppet/4.6/reference/lang_resources_advanced.html#setting-attributes-from-a-hash). PPS: increased difficulty level, some parameter names (of the common parameters set) change across defined types [I really need something like a preprocessor, but it's gotta be triggered automatically]

ruby methods .map, .each, .gsub changes overview for puppet v3 & v4

$
0
0
Hey Guys

Can anyone give me a good overview of the changes between ruby in puppet v3 & v4.
In particular the methods named above.

I need to cvt our p3 (3.2.2) system to p4, whilst at the same time, ensure that our code will run against both versions of puppet until we have fully converted.

At the moment, I frequently come across msgs like Detail: undefined method `gsub' for nil:NilClass for the above methods, and have to recode them.
This is doubly tricky as I know nothing about ruby ;)

Any help gratefully received

Chris

ruby / jruby : cannot see mysql file

$
0
0
Hi Guys,

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Internal Server Error: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- mysql but rpm -qa|grep -i mysql ruby-mysql-2.8.2-1.el6.x86_64 so why do I get his error?
Chris

client puppet 3.3.1; server 4.5.0

puppet broken on ruby version

$
0
0
Here is what happened: I installed puppet 3.8 from this repo https://apt.puppetlabs.com/puppetlabs-release-trusty.deb OS: Ubuntu 14.04 Trusty It was using the standard system version of ruby 1.9 Then I installed ruby2.3 as I need to work with this version for some apps When I tried to run a puppet module, I got a whole bunch of Evaluation errors. I removed ruby2.3 as I saw its not supported by Puppet 3 or 4. Then I installed ruby2.1. I need at least ruby 2.1 for my app to work and I see this has been tested with Puppet. However, I keep getting this now root@server02:~# puppet version /usr/bin/env: ruby2.3: No such file or directory root@server02:~# facter /usr/bin/env: ruby2.3: No such file or directory So I think I need to somehow change where it is looking for ruby. If not, please advise of solution to this. UPDATE: I removed everything puppet and ruby related from the system including the files in /usr/local/bin puppet and facter. It seems the installer is not recreating these files. How can I recreate the files? root@server02:/home/ubuntu# puppet --version bash: /usr/local/bin/puppet: No such file or directory UPDATE: Reboot fixed the last issue. Brought the files in /usr/local/bin. Anyone know why? I would prefer to understand what happened here. However getting puppet to work with ruby2.1 is still causing pain. I installed it but now its not finding augeas whereas all the correct augeas packages seem to be installed.

Unable to point puppet to latest Ruby

$
0
0
I have installed Puppet as per official documentation and I have got installed Ruby 1.8.7. But via rvm I have installed ruby 2.3.3 and then installed rack and passenger gems with `gem install rack passenger` and installed `passenger-install-apache2-module` successfully. I made changes accordingly to puppetmaster.conf and placed it in conf.d directory of httpd service. After starting httpd service I have given as `puppet cert` and its showing below errors [root@lab puppet-fundamentals-puppetmaster]# puppet cert /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- json (L oadError) from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/module.rb:3 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser/files.rb:1 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser/templatewrapper.rb:1 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser/scope.rb:6 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser/methods.rb:2 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser/ast/method_call.rb:2 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser/ast.rb:115 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser/parser.rb:11 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/parser.rb:4 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet.rb:282 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/site_ruby/1.8/puppet/util/command_line.rb:12 from /usr/bin/puppet:7:in `require' I don't understand why Puppet still looking over ruby 1.8 even I did mention as in puppetmaster.conf PassengerRoot /usr/local/rvm/gems/ruby-2.3.3/gems/passenger-5.1.2 PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.3.3/wrappers/ruby Is there any way I can tell Puppet to look over ruby-2.3.3 as default ruby for all its needs ? [root@lab ~]# puppet --version 3.8.7 [root@lab ~]# [root@lab ~]# ruby -v ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux] [root@lab ~]# rvm all ruby list rvm rubies =* ruby-2.3.3 [ x86_64 ] Thank you.

provider from puppet 3 doesn't work with puppet 4 - gem

$
0
0
Hi, i try to resurrect an own module which allows me to create kvm instances via libvirt. The module used the type/provider specs. At one point of the execution the code stops with the error > Error: /Stage[main]/Kvm/Virt[vm001]: Provider libvirt is not functional on this host I found in the provider the line > confine :feature => :libvirt which guided me to the line for the feature add > Puppet.features.add(:libvirt, :libs => ["libvirt"]) If i remove the libs section i get on puppet execution an > Error: /Stage[main]/Kvm/Virt[vm001]: Could not evaluate: uninitialized constant Libvirt The module took care that the ruby-libvirt module is installed on the host. I can see it with the command [root@ml110 tmp]# gem list --local *** LOCAL GEMS *** bigdecimal (1.2.0) io-console (0.4.2) json (1.7.7) psych (2.0.0) rdoc (4.0.0) ruby-libvirt (0.5.2) As far i can remember the puppet-agent comes with a own ruby, that whould mean that i whould have to install the ruby libs to this ruby and not to the system ones' how do i do that. Or do i search in the wrong direction? Is it an completely different error cause? br

ruby code in template not working with Puppet 4.x anymore

$
0
0
I used following code to generate random orders of LDAP servers in client config file, it won't change the orders in next puppet agent run. However in Puppet v4+, it doesn't seem to work any more, every time when agent runs, it changes the order in the config file. Does anyone know why? ldap_uri = <% server_list = @_ldap_servers.dup server_list.size.times do server = server_list[rand(server_list.size)] -%>ldaps://<%= server -%>/ <% server_list.delete(server) end %> PS: `$_ldap_servers` is a list value (ex, `$_ldap_servers = ['ldap1', 'ldap2', 'ldap3']`)

'pe-bundler' missing in Puppet Enterprise 2016.4.6??

$
0
0
Hi there, The '**pe-bundler**' was existed in previous version **2016.4.5** but missing in **2016.4.6**, is that normal? And where the reason I could find?

How do I resolve a file reference via Ruby in a custom module

$
0
0
Hi everyone, I have what I think should be a simple question, but for the life of me just can't find a solution. Hoping you can help, here goes... I'm trying to build a custom module that makes a couple of quick REST calls (I know, kind of "unpuppety"). I've got everything up and running, except for I can't figure out how to read the contents of a "puppetted" file reference from Ruby. In the below resource declaration, I have hardcoded the location of a file that lives inside of my module. This works just fine for my testing, but is not adequate when run on my server. elasticsearch_template { 'analytic_template': ensure => present, servername => 'localhost', port => '9201', ssl => false, content => 'C:\Users\specnik\repos\elasticsearch\files\template_1.json' # content => 'puppet:///modules/elasticsearch/template_1.json', } What I think best practice would be is to reference a file from within a module like I have in the commented line above. The question is, with that type of reference, how do I read the file from Ruby? Right now I am using the following, which works for the hard coded file reference only: Puppet::FileSystem.read(resource[:content]) Surely there must be an API to sort this kind of thing out?? Has anybody come across this type of thing before and could point me to a solution? Oh, and the reason I am not using an existing elasticsearch module is because I am spinning up a container with elasticsearch and not trying to install directly on the machine. Thanks! Scott

Fact will only be set correctly after two runs (dynamic calculation via python script)

$
0
0
Hi, I'm fighting a little bit with setting some dynamically calculated kernel parameters on RHEL (7) systems using a ruby file. In my structure the files are under `/lib/facter/.rb` (what should be correct as it works at least after the second run). Content of this file: require 'facter' Facter.add("") do confine :kernel => :linux, :operatingsystem => %w{CentOS Fedora RedHat} setcode do Facter::Util::Resolution.exec('') end end So now I'm wondering why this only works when puppet runs twice. I already put the script (which calculates the value dynamically) distribution to another module so that it is definitively there when this module (where `factor` has to set this parameter) runs. These two modules are configured that they depend on each other of course. In `metadata.json` of the ``: "dependencies": [ {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}, {"name":"","version_requirement":">= 0.1.2"} ] But this does not change anything. Still two runs are necessary that it works correctly. Does anyone have a tip for me? Thanks in advance

Custom fact being applied to all servers how to avoid that

$
0
0
Custom fact Tomcat_version is being applied to all boxes whether they have Tomcat installed or not. For those boxes with no Tomcat installed the ruby script breaks and comes back with an error, which shouldn't be happening. Coming up with a way so that this doesn't happen. The facter error for Tomcat is very simple... Boxes that have no Tomcat installed are failing to produce the custom fact. That's because the custom fact design was thought for guidewire boxes. We didn't have all the boxes in mind when we designed that. For now just need to come up with an approach on how to go about fixing that. Facter.add(:tomcat_version) do confine :kernel => 'windows' setcode do version = Facter::Core::Execution.exec('c:\tempex\bin\version.bat 2>&1') version = version.split("\n")[5] version = version.split("\/")[1] version = version.split("\n")[0] end

Custom fact being applied to all servers how to avoid that part II

$
0
0
This is a continuation from https://ask.puppet.com/question/32776/custom-fact-being-applied-to-all-servers-how-to-avoid-that/ Since it was decided to go in another direction a new question is being ask. The idea is to look which exe file we have in the folder. If the file is tomcat6, then we know we're running version 6, if you have tomcat8, we're running version 8. We'll only care for the major version (6, 7, 8, etc). Still being done in puppet ruby script. This way when we look at the variable in puppet it will come up instead of it just coming up as variable. Script below would need to be easily modify for future use regarding tomcat. original script Facter.add(:tomcat_version) do confine :kernel => 'windows' setcode do if File.exist? 'C:\tempex\bin\tomcat6.exe' version = Facter::Core::Execution.exec('c:\tempex\bin\version.bat 2>&1') version = version.split("\n")[5] version = version.split("\/")[1] version = version.split("\n")[0] end end tomcat will be stored here C:\tempex\bin\tomcat6.exe or 7 or 8

testing facter code for the first time

$
0
0
Still pretty new to puppet and im trying to test out a script I have for a new facter i created. Problem is i have never tested ruby code for puppet before so i don't know how to begin. I have the script design that i believe should work but no knowledge on how to test to see if it gives me results. testing it on my local machine for now which has puppet agent installed for windows. Any help that be given would be much appreciated.

Custom fact being applied to all servers how to avoid that part III

$
0
0
Right now i have a ruby script that pulls tomcat location from version.bat. Problem with that is in some of the jobs it works fine and displays where tomcat is installed. But for others for tomcat home in puppet it shows up as `Variable.` That being the case I use previous suggested code from the links below to modify my original script to allow me to not only identify whether tomcat is installed on my machine or not if it is the script continues and then displays location in puppet. If there no tomcat found scripts ends so the puppet job doesn't come up with an error saying `error while resolving custom fact Tomcat_home`. the script i have doesn't cause any error for tomcat home if tomcat is not found but it doesn't do anything else and don't know why. My modified script Facter.add(:tomcat_home) do confine :kernel => 'windows' setcode do home = Dir.glob('C:\tempex?').sort().last() home = home.match(/\d/) if home.is_a?(String) home end end The original script that was being used: Facter.add(:tomcat_home) do confine :kernel => 'windows' # The Version command will produce an output similar to the following: # Using CATALINA_BASE: "C:\tempex" # Using CATALINA_HOME: "C:\tempex" # Using CATALINA_TMPDIR: "C:\tempex\temp" # Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_144\jre" # Using CLASSPATH: "C:\tempex\bin\bootstrap.jar;C:\tempex\bin\tomcat-juli.jar" # Server version: Apache Tomcat/8.0.45 # Server built: Jun 26 2017 20:06:07 UTC # Server number: 8.0.45.0 # OS Name: Windows Server 2012 # OS Version: 10.0 # Architecture: amd64 # JVM Version: 1.8.0_144-b01 # JVM Vendor: Oracle Corporation # # The following code manipulates the output text to get only the Tomcat Home line (line 1), and the specific path. # Splitting the line where the blank space is found, then taking the third text chunk ([2], since it starts on [0]) # and finally trimming off the double quotes. setcode do home = Facter::Core::Execution.exec('c:\tempex\bin\version.bat 2>&1') home = home.split("\n")[1] home = home.split(" ")[2] home = home.tr('"', '') end end End result should be a script that will be able to tell tomcat is installed and then tell puppet where it is for home. When it sees there no tomcat script will end causing puppet to run with no error. Custom fact being applied to all servers how to avoid that part I: https://ask.puppet.com/question/32776/custom-fact-being-applied-to-all-servers-how-to-avoid-that/ Custom fact being applied to all servers how to avoid that part II: https://ask.puppet.com/question/32793/custom-fact-being-applied-to-all-servers-how-to-avoid-that-part-ii/

How to get tomcat_version to display the whole version of tomcat in script instead of just the first number

$
0
0
With the input provided to me from this site i was able to modify a script that match what i needed for my tomcat_version fact. The only problem is that it does not display the whole version of the tomcat file just the one number like tomcat 6, 7, 9 instead of 6.2.1 for example. This wouldn't be a problem if it wasn't for another class reference this file that being the case i need a way to display the full version of tomcat. Avoiding using the `version.bat` file since it has cause us some issues and we are trying to move away from it . Facter.add(:tomcat_version) do confine :kernel => 'windows' setcode do if version = Dir.glob('C:\guidewire\bin\tomcat?.exe').sort().last() version = version.match(/\d+/) if version.is_a?(String) else version = 'Tomcat not installed' end end end example of what its shows right now ![image description](/upfiles/15132936441190557.png)

Having puppet run powershell script in ruby

$
0
0
I have a powershell script we are using to create our folders, shares, and there is a register entry for env enablement. My job is to create a ruby script that dos the same so it can be run in puppet. While going over the powershell I notice what was being used in powershell to give us access to some share files. My question being what would be the ruby equivalent in puppet for script portion shown below. or would it be better to create a ruby script in puppet that runs our powershell script. #Copy Scripts Copy-Item -Path "X:\Information Technology\DBA\PowerShell_Scripts\ServerSetup\DW\*.*" -Destination "D:\Scripts\DW" if(!(Get-SBShare -Name SIS -ea 0)){ New-SBShare -Name SIS -Path D:\SIS } Grant-SbShareAccess -Name SIS -AccountName "Admin\SQLAdmins" -AccessRight Full -Force Grant-SbShareAccess -Name SIS -AccountName "administrators" -AccessRight Full -Force Revoke-SbShareAccess -Name SIS -AccountName "Everyone" -Force
Viewing all 89 articles
Browse latest View live


Latest Images