2

how i can inherit variable from puppet manifest in facter custom fact? in this case $job_name varible. I want use same custom fact with different envs.

if $facts['hostname'] =~ /.*name.*/ {

$job_name = 'test'

        file {  "/opt/$job_name":
                ensure => directory,
                owner  => 'root',
                group  => 'root',
                mode   => '0775',
             }


        file { "/opt/$job_name/version.$job_name":
                ensure => present,
                owner  => 'root',
                group  => 'root',
                mode   => '0644',
                #notify => Exec["update_test"],
                source => "puppet:///modules/test/version.$job_name",
             }


     if $facts['check_version'] == "aasdadsadasd" {

        file {  "/opt/$job_name/bla2":
                ensure => directory,
                owner  => 'root',
                group  => 'root',
                mode   => '0775',
             }


     }

my custom fact rb code is

require 'facter'
Facter.add(:check_version) do
  setcode do
    Facter::Core::Execution.exec("/bin/cat /opt/$job_name/version.$job_name")
  end
end

thanks in advance

antimion
  • 61
  • 5

1 Answers1

3

If you want to use a manifest variable in a custom fact, you can't. This is because facts are evaluated on the client before the catalog (collection of manifests) is compiled. So at the point that your custom fact is run, the variable $job_name doesn't actually exist yet.

bodgit
  • 4,661
  • 13
  • 26