Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Should I not be using a 'function' here?

I wanted to use more ruby instead of exec'ing out to a shell script that queries a Oracle DB to get the list of hostnames of my DNS servers, so I updated my custom function list_allow_upates.rb to use oci8 and resolv. I install ruby-oci8 on my puppet master (PE 2.7) but I guess I didn't understand that I would have to install ruby-oci8 on ALL my puppet agents. I do not want to have to do that (install ruby-oci8 on all my puppet agents). Here's what happen after I updated the custom function, list_allow_updates.rb on my master and then ran puppet agent -t on my agent ...

[root@my-puppet-agent ~]# puppet agent -t
info: Retrieving plugin
notice: /File[/var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb]/content: 
--- /var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb    2013-04-08 16:42:31.179772751 -0400
+++ /tmp/puppet-file20130412-19495-llnpp7-0     2013-04-12 15:29:44.841768581 -0400
@@ -1,5 +1,34 @@
 module Puppet::Parser::Functions
+       require 'resolv'
+       require 'oci8'
+
        newfunction(:list_allow_updates, :type => :rvalue) do |args|
-               Puppet::Util.execute( '/etc/puppetlabs/puppet/modules/myzone/scripts/list_internal_dns_servers.sh' )
+               conn = OCI8.new('user', 'passwd' )
+               conn.exec(<<-SQL) do |row|
+select 
+       h.hostname 
+from 
+               host h
+       ,       eman_server es 
+where 
+               es.cid = h.cid 
+       and     es.eman_server_type = 'DNS' 
+       and     h.hostname not like '%lab%'
+       and     h.hostname not like '%-new%'
+       and     h.hostname not like '%-old%'
+order by 
+       h.hostname
+SQL
+       # dns servers that have lab -new or -old in their hostnames are not DNS servers we care about
+
+                       hostName        = row[0].to_s 
+                       ip              = Resolv.getaddress(hostName)
+                       puts "          #{ip};  \#      #{hostName}"
+               end
        end
 end

notice: /File[/var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb]/content: content changed '{md5}94f20fcc0daabb4b9373226d25d12b56' to '{md5}05d9507bd3ea327255ad5950c196d2a0'
notice: /File[/var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.backup]/ensure: defined content as '{md5}94f20fcc0daabb4b9373226d25d12b56'
info: Loading downloaded plugin /var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb
err: Could not load downloaded file /var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb: no such file to load -- oci8
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/root_home.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/concat_basedir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/custom_auth_conf.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/puppet_vardir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/pe_version.rb
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template myzone/named.conf.erb:
  Filepath: oci8.c
  Line: 513
  Detail: ORA-12154: TNS:could not resolve the connect identifier specified
 at /etc/puppetlabs/puppet/modules/myzone/manifests/init.pp:13 on node my-puppet-agent
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run

... my question is:

How can I avoid having to install ruby-oci8 on all my agents? Should I be using custom facts instead?

click to hide/show revision 2
TNS error ORACLE_HOME

Should I not be using a 'function' here?

I wanted to use more ruby instead of exec'ing out to a shell script that queries a Oracle DB to get the list of hostnames of my DNS servers, so I updated my custom function list_allow_upates.rb to use oci8 and resolv. I install ruby-oci8 on my puppet master (PE 2.7) but I guess I didn't understand that I would have to install ruby-oci8 on ALL my puppet agents. I do not want to have to do that (install ruby-oci8 on all my puppet agents). Here's what happen after I updated the custom function, list_allow_updates.rb on my master and then ran puppet agent -t on my agent ...

[root@my-puppet-agent ~]# puppet agent -t
info: Retrieving plugin
notice: /File[/var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb]/content: 
--- /var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb    2013-04-08 16:42:31.179772751 -0400
+++ /tmp/puppet-file20130412-19495-llnpp7-0     2013-04-12 15:29:44.841768581 -0400
@@ -1,5 +1,34 @@
 module Puppet::Parser::Functions
+       require 'resolv'
+       require 'oci8'
+
        newfunction(:list_allow_updates, :type => :rvalue) do |args|
-               Puppet::Util.execute( '/etc/puppetlabs/puppet/modules/myzone/scripts/list_internal_dns_servers.sh' )
+               conn = OCI8.new('user', 'passwd' )
+               conn.exec(<<-SQL) do |row|
+select 
+       h.hostname 
+from 
+               host h
+       ,       eman_server es 
+where 
+               es.cid = h.cid 
+       and     es.eman_server_type = 'DNS' 
+       and     h.hostname not like '%lab%'
+       and     h.hostname not like '%-new%'
+       and     h.hostname not like '%-old%'
+order by 
+       h.hostname
+SQL
+       # dns servers that have lab -new or -old in their hostnames are not DNS servers we care about
+
+                       hostName        = row[0].to_s 
+                       ip              = Resolv.getaddress(hostName)
+                       puts "          #{ip};  \#      #{hostName}"
+               end
        end
 end

notice: /File[/var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb]/content: content changed '{md5}94f20fcc0daabb4b9373226d25d12b56' to '{md5}05d9507bd3ea327255ad5950c196d2a0'
notice: /File[/var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.backup]/ensure: defined content as '{md5}94f20fcc0daabb4b9373226d25d12b56'
info: Loading downloaded plugin /var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb
err: Could not load downloaded file /var/opt/lib/pe-puppet/lib/puppet/parser/functions/list_allow_updates.rb: no such file to load -- oci8
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/root_home.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/concat_basedir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/custom_auth_conf.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/puppet_vardir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/pe_version.rb
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template myzone/named.conf.erb:
  Filepath: oci8.c
  Line: 513
  Detail: ORA-12154: TNS:could not resolve the connect identifier specified
 at /etc/puppetlabs/puppet/modules/myzone/manifests/init.pp:13 on node my-puppet-agent
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run

... my question is:

How can I avoid having to install ruby-oci8 on all my agents? Should I be using custom facts instead?

Update for TNS error:

It looks like the TNS error is cause because the ORACLE_HOME environment var is not set in the puppet master ...

[red@my-puppet-master ~]$ env | grep ORA
ORACLE_HOME=/opt/oracle10g
[red@my-puppet-master ~]$ unset ORACLE_HOME
[red@my-puppet-master ~]$ env | grep ORA
[red@my-puppet-master ~]$ ./test.rb 
./test.rb:27: warning: don't put space before argument parentheses
Warning: NLS_LANG is not set. fallback to US7ASCII.
oci8.c:513:in oci8lib.so: ORA-12154: TNS:could not resolve the connect identifier specified (OCIError)
        from /opt/puppet/lib/ruby/site_ruby/1.8/oci8/oci8.rb:148:in `initialize'
        from ./test.rb:7:in `new'
        from ./test.rb:7

... how would I get ORACLE_HOME set for my custom function?