Creating new “fact” in Foreman (Puppet master) and publish it to all nodes

Hi all,

I’m trying to create new fact “check if a file exists” I tried to follow
the instruction in
Foreman :: Manual with no
luck.

I want to create fact that will check that for example “/etc/test” file
exists. I’m working couple of days on it and can’r figure it out.

If someone can give example or advise how to create that fact and publish
it for all nodes it will be great.

Please assist.

Thanks,

Eddie.

anyone?

··· On Tuesday, June 16, 2015 at 12:12:07 PM UTC+3, Eddie Mashayev wrote: > > Hi all, > > > I’m trying to create new fact “check if a file exists” I tried to follow > the instruction in > http://theforeman.org/manuals/1.8/index.html#3.5.5FactsandtheENC with no > luck. > > > > I want to create fact that will check that for example “/etc/test” file > exists. I’m working couple of days on it and can’r figure it out. > > > > If someone can give example or advise how to create that fact and publish > it for all nodes it will be great. > > > > Please assist. > > > Thanks, > > Eddie. >

Found a solution:

Create ruby script in:
root@foreman]# cat
/etc/puppet/environments/production/modules/customfacts/lib/facter/check_file_exsist.rb
Facter.add('check_nails_exsist') do
setcode do
File.exists?('/etc/NONAILS')
end
end

We are checking if /etc/NONAILS exist, if yes return true else false.

Create puppet manifest to ensure the service running, if file exist stop
the server:
[root@foreman]# cat
/etc/puppet/environments/production/modules/check_service/manifests/init.pp

Class: check_service

class check_service {
if $check_nails_exsist == 'true' {
service { 'nails':
ensure => "stopped",
enable => false,
hasstatus => false,
hasrestart => false,
}
}
else {
service { 'nails':
ensure => "running",
enable => true,
hasstatus => false,
hasrestart => true,
}
}
}

As for as I know Puppet not supports "if statements" in service class, so
this is the correct way to do it with Facter engine.

Hope it helped.

··· On Tuesday, June 16, 2015 at 4:44:17 PM UTC+3, Eddie Mashayev wrote: > > anyone? > > On Tuesday, June 16, 2015 at 12:12:07 PM UTC+3, Eddie Mashayev wrote: >> >> Hi all, >> >> >> I’m trying to create new fact “check if a file exists” I tried to follow >> the instruction in >> http://theforeman.org/manuals/1.8/index.html#3.5.5FactsandtheENC with no >> luck. >> >> >> >> I want to create fact that will check that for example “/etc/test” file >> exists. I’m working couple of days on it and can’r figure it out. >> >> >> >> If someone can give example or advise how to create that fact and publish >> it for all nodes it will be great. >> >> >> >> Please assist. >> >> >> Thanks, >> >> Eddie. >> >