Puppet custom facts check zabbix user

asked 2018-02-19 03:57:43 -0600

Anton gravatar image

Good afternoon! I'm trying to check the zabbix user using puppet custom facts:

File facts.d / zabbix_user.rb

Facter.add(:zabbix_user) do
    confine :kernel => :linux
    setcode do
    %x{grep zabbix /etc/passwd |cut -f1 -d:}.chomp
    end
end

I do a check like this:

if $zabbix_user == "zabbix"

Puppet 3.8

When you run puppet agent --test prints On centos6

/usr/lib/ruby/site_ruby/1.8/facter/util/directory_loader.rb:75: command not found: /var/lib/puppet/facts.d/zabbix_user.rb

On centos7

/var/lib/puppet/facts.d/zabbix_user.rb: line 1: syntax error near unexpected token `:zabbix_user'
/var/lib/puppet/facts.d/zabbix_user.rb: line 1: `Facter.add(:zabbix_user) do'
Fact file /var/lib/puppet/facts.d/zabbix_user.rb was parsed but returned an empty data set

Where was I wrong? Can you help?

edit retag flag offensive close merge delete

Comments

(w.r.t. the centos7 error) I THINK you either need to at least return an empty string, or not even 'add' the fact... if you move the logic of gathering the information outside of the 'facter.add()do ... end' block, and only add the fact if it's a non-empty set

DarylW gravatar imageDarylW ( 2018-02-19 10:47:09 -0600 )edit

Also, I think you don't usually do a raw 'exec' in ruby, you typically would use the `Facter::Core::Execution.exec` method as documented on https://puppet.com/docs/facter/3.9/fact_overview.html, which may have different path/lifecycle characteristics per OS

DarylW gravatar imageDarylW ( 2018-02-19 10:50:00 -0600 )edit

I modified fact zabbix_group.sh: #!/bin/bash if grep -q ^zabbix: /etc/group; then echo "zabbix_group=zabbix" else echo "zabbix_group=''" fi It works Thank you

Anton gravatar imageAnton ( 2018-02-19 22:50:40 -0600 )edit