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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.