jcbollinger wrote: > On Thursday, May 16, 2019 at 10:50:45 AM UTC-5, Helmut Schneider > wrote: > > > I don't want to install netplan but if it exists do the needful: > > I reiterate Ben Ford's comments: This is generally considered an > anti-pattern. > > It is better from an administrative perspective for you to know which > systems are supposed to have netplan, and to unconditionally ensure > that it is both installed and properly configured on those systems. > You could go so far as to ensure it absent from other machines, > though whether that's appropriate is a policy question whose answer > will vary. In any case, it is not only reasonable but safer for all > concerned to demand that the identities of machines for which you are > going to manage netplan configuration be statically known to you.
I see your point and in 99% of my tasks with Puppet I agree. > With that said, if you insist on treading this path anyway then a > custom fact is indeed the right way to convey the wanted information > to Puppet, whether that's the version of netplan that's installed, if > any, or merely whether netplan is installed at all. For that you'll > want either a fact specific to that purpose (e.g. > $::netplan_version), or a more general fact from which you can glean > the information (e.g. $::installed_packages). There is no way to > parameterize a fact so that it has different meaning depending on how > it is evaluated. Nevertheless knowing what packages are installed might help me, too, and although my ruby knowledge is very rudimentary here is some output: #!/usr/bin/ruby Facter.add('installed_packages') do confine :osfamily => /freebsd|debian/ setcode do begin packages_hash = {} if Facter.value(:osfamily) == 'Debian' packages = Facter::Util::Resolution.exec('/usr/bin/dpkg -l | /bin/grep ^ii | /usr/bin/awk \'{print $2"|"$3}\'') elsif Facter.value(:osfamily) == 'FreeBSD' packages = Facter::Util::Resolution.exec('/usr/sbin/pkg info | /usr/bin/awk \'{print $1}\' | /usr/bin/sed -E \'s#-([[:digit:]])#\|\1#g\'') end packages.each_line do |package| if package name,*version = package.chomp.split(/\|/) packages_hash[name] = version.join("") end end packages_hash rescue end end end -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/xn0lu5wgxchwp1000%40news.gmane.org. For more options, visit https://groups.google.com/d/optout.