Puppet Best Practices by Chris Barbour
Author:Chris Barbour
Language: eng
Format: mobi, epub
Tags: COMPUTERS / System Administration / General
ISBN: 9781491922965
Publisher: O’Reilly Media
Published: 2015-03-16T16:00:00+00:00
Variable Qualifiecation
Local variables should be unqualified, global variables should be fully qualified, and fully qualified out-of-scope variable references should be avoided if possible.
Fully qualifying variable names accomplishes two goals:
Clarifies your intent
Disambiguates local and global variables
When a variable is fully qualified, it becomes clear that your module is attempting to consume a top level variable, and eliminates the possibility that you simply forgot to define that variable or are attempting to inherit a variable from a higher scope. This disambiguation is important when you revisit your code in the future, either to extend the code or debug a problem.
Many validation tools also assume that unqualified variables are local, and will throw a warning if the variable is not defined in scope. With puppet-lint, this behavior can be disabled, however I recommend against doing so as it’s a useful way to catch subtle bugs.
While you can fully qualify references to local variables, using unqualified names makes it clear at a glance that the variable is local and has been defined in the current scope. This hint again is used by the validators.
Finally, I strongly recommend against creating inter-class variable references using fully qualified variable names. Such references are a useful stop-gap measure when upgrading code that relies on variable inheritance, however it usually violates the principle of separation of concerns. A major issue with inter-class variable references is that there’s no way to tell from the referenced class that such a reference exists. As a result, it’s very easy to break the reference when re-factoring code. Instead, consider parameterizing your classes, using class parameters to pass data from one module to another. A side benefit of this approach is that it tends to reduce and eliminate circular dependencies.
Example 4-20. Passing variables using fully qualified variables
class parent { $foo = 'alpha' } class parent::child { $foo = $::parent::foo alert($foo) #Prints 'alpha' }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Disaster & Recovery | Email Administration |
Linux & UNIX Administration | Storage & Retrieval |
Windows Administration |
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Grails in Action by Glen Smith Peter Ledbrook(7696)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(6531)
Azure Containers Explained by Wesley Haakman & Richard Hooper(6519)
Running Windows Containers on AWS by Marcio Morales(6044)
Kotlin in Action by Dmitry Jemerov(5062)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(4895)
Combating Crime on the Dark Web by Nearchos Nearchou(4477)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4414)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(4302)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4151)
The Age of Surveillance Capitalism by Shoshana Zuboff(3946)
Python for Security and Networking - Third Edition by José Manuel Ortega(3712)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3503)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3387)
Mastering Python for Networking and Security by José Manuel Ortega(3344)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3327)
Blockchain Basics by Daniel Drescher(3292)
Learn Wireshark by Lisa Bock(3226)
