Ask Your Question

fact vs variable (scope question)

asked 2017-06-08 13:01:36 -0600

sboss gravatar image

if I have a fact called datacenter, and my class has a variable declared (in the console) called datacenter, which one gets presence over the other? Or is this going to be a big "mess" and have to have unique names? hopefully not.


edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2017-06-09 09:57:30 -0600

Mr_Sharma gravatar image

If you define the datacenter variable in local scope it should override the facter value of datacenter fact. You can read more about scope of variables and facts here.

Please note there are few facts which can't be overridden or can't be defined even in local scope. Hope it helps.

edit flag offensive delete link more

answered 2017-06-11 09:42:12 -0600

Henrik Lindberg gravatar image

If you have a variable in scope it wins over a top scope variable such as facts as they are set directly in top scope. Note that it is recommended to reference facts via the $facts hash, in your case use $facts['datacenter'].

edit flag offensive delete link more

answered 2017-06-09 10:06:28 -0600

sboss gravatar image

rajeevsharma, thank you for your prompt answer. It is what I hoped for and expected. Thank you!!

edit flag offensive delete link more


Plz vote if answer was useful.

Mr_Sharma gravatar imageMr_Sharma ( 2017-06-09 18:41:54 -0600 )edit

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


Asked: 2017-06-08 13:01:36 -0600

Seen: 61 times

Last updated: Jun 11 '17