local volumes for facter #4115

6 views
Skip to first unread message

Matt

unread,
Oct 6, 2011, 6:35:09 AM10/6/11
to puppe...@googlegroups.com
I've used the following plugin in both our CentOS and Ubuntu installs
to provide a list of local volumes. It enables us to monitor disks
which get mounted/unmounted regularly during failover etc. Any
recommendations to get it in to facter?

# df.rb
require 'facter'

diskvols = Array.new
volumes = String.new
df_output = %x{/bin/df -lP}
result = $?.to_i
if result == 0
df_output.each do |vol|
diskvols.push(vol)
end
diskvols.delete_at(0)
diskvols.each do |vol|
volumes = volumes + ' ' + vol.split(' ')[5]
end
Facter.add("local_volumes") do
setcode do
volumes.strip()
end
end
end

Jacob Helwig

unread,
Oct 6, 2011, 2:27:47 PM10/6/11
to puppe...@googlegroups.com

The biggest thing (other than adding tests for it), would be moving all
of the things you're doing outside of the setcode block into a function
called from the setcode block, or into the setcode block itself. See
the recent discussion on puppet-dev about thread-safety in Facter[1] for
some reasons why.

[1] http://groups.google.com/group/puppet-dev/browse_thread/thread/ccd4a7d762651aa5/5bb09a83e981cc6c

--
Jacob Helwig

signature.asc

Krzysztof Wilczynski

unread,
Oct 7, 2011, 6:20:54 AM10/7/11
to Puppet Developers
Hello,
> [1]http://groups.google.com/group/puppet-dev/browse_thread/thread/ccd4a7...
>

+1

I would also recommend changing the output format a little so it is a
comma-separated list (which follows what other facts usually do).

Current output:

local_volumes => / /dev /dev/shm /var/run /var/lock /lib/init/rw /boot

Preferred output:

local_volumes => /,/dev,/dev/shm,/var/run,/var/lock,/lib/init/rw,/boot

KW

Krzysztof Wilczynski

unread,
Oct 7, 2011, 6:24:54 AM10/7/11
to Puppet Developers
Hello,

[...]
> +1
>
> I would also recommend changing the output format a little so it is a
> comma-separated list (which follows what other facts usually do).
>
> Current output:
>
> local_volumes => / /dev /dev/shm /var/run /var/lock /lib/init/rw /boot
>
> Preferred output:
>
> local_volumes => /,/dev,/dev/shm,/var/run,/var/lock,/lib/init/rw,/boot

Also, consider using Facter::Util::Resolution#exec over %x{} :-)

KW

Stefan Schulte

unread,
Oct 7, 2011, 8:50:16 AM10/7/11
to Puppet Developers

and use #each_line instead of #ach for strings because #each does not
work for all ruby versions.

-Stefan

Reply all
Reply to author
Forward
0 new messages