Ask Your Question
1

fact vs variable (scope question)

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

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.

thanks

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

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

rajeevsharma 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
2

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

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
0

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

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

Comments

Plz vote if answer was useful.

rajeevsharma gravatar imagerajeevsharma ( 2017-06-09 18:41:54 -0500 )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

Stats

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

Seen: 48 times

Last updated: Jun 11