Ask Your Question
0

access facter 3 values

asked 2015-08-19 23:29:41 -0500

Ath gravatar image

I want to retrieve a fact for using in a custom fact

facter os
{
  architecture => "amd64",
  distro => {
    codename => "trusty",
    description => "Ubuntu 14.04.2 LTS",
    id => "Ubuntu",
    release => {
      full => "14.04",
      major => "14.04"
    }
  },
  family => "Debian",
  hardware => "x86_64",
  name => "Ubuntu",
  release => {
    full => "14.04",
    major => "14.04"
  },
  selinux => {
    enabled => false
  }
}

How to access this in a Custom fact code

Facter.add(:datacenter) do
        setcode do
        fam=Facter.value(::os[family])
                if fam == "Debian"
                        "Bangalore"
                else
                        "Delhi"
                end
        end
end
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-08-20 14:13:41 -0500

mat1010 gravatar image

updated 2015-08-20 14:14:01 -0500

Referring to this the follwoing will still work

Facter.add(:datacenter) do
        setcode do
        fam=Facter.value(:osfamily)
                if fam == "Debian"
                        "Bangalore"
                else
                        "Delhi"
                end
        end
end

For me this works fine.

edit flag offensive delete link more
0

answered 2015-08-23 07:44:57 -0500

Ath gravatar image

One way I found is

> Facter.add(:datacenter) do
        setcode do
        fam=Facter.value(:os)

                if fam['family'] == "Debian"
                        "Bangalore"
                else
                        "Delhi"
                end
        end
end
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-08-19 23:29:41 -0500

Seen: 248 times

Last updated: Aug 23 '15