le 02/08/2017 à 14:05

?Customized facts walkthrough
Personalized facts
Lengthen Facter by composing your very own personalized facts to provide you with details to Puppet.
Adding custom made facts to Facter
Every so often you wish to be able to jot down conditional expressions determined by site-specific info that just isn’t attainable by way of Facter, or perhaps you’d like to include it in a very template.
Since you can’t include arbitrary Ruby code on your manifests, the optimum alternative is to incorporate a new fact to Facter. These increased facts can then be distributed to Puppet clients and are on the market for use in manifests and templates, just like any other fact would be.
Note: Facter 3.0 removed the Ruby implementations of some characteristics and replaced them by having a custom made facts API. Any personalized fact that requires just one within the Ruby documents previously stored in lib/facter/util will fail using an error. For increased advice, see the Facter 3.0 release notes .
The concept
You can still increase new facts by producing snippets of Ruby code relating to the Puppet master. Puppet then works by using Plugins in Modules to distribute the facts to the client.
Loading personalized facts
Facter offers you a number of methods of loading facts:
$LOAD\_PATH. or the Ruby library load path
The --custom-dir command line option.
The environment variable ‘FACTERLIB’
One can use these methods of loading facts to do things like exam documents locally before distributing them, otherwise you can arrange to have a particular list of facts offered on certain machines.
Employing the Ruby load path
Facter searches all directories inside of the Ruby $LOAD_PATH variable for subdirectories named ‘facter’, and loads all Ruby documents in those directories. For those who had some directory in the $LOAD_PATH like
/lib/ruby. put in place like this:
Facter would try to load ‘facter/system_load.rb’, ‘facter/users.rb’, and ‘facter/rackspace.rb’.
Choosing the --custom-dir command line option
Facter can take many different --custom-dir solutions in the command line that specifies an individual directory to search for tailor made facts. Facter attempts to load all Ruby documents inside the specified directories. This enables you to definitely do something like this:
Implementing the FACTERLIB environment variable
Facter also checks the environment variable FACTERLIB for a delimited (semicolon for Windows and colon for all other platforms) list of directories, and tries to load all Ruby documents in those directories. This permits you to definitely do something like this:
Note: Changes in built-in pluginsync service in Facter 3
Facter two.four deprecated Facter’s guidance for loading facts by way of Puppet’s pluginsync (the -p option), and Facter 3.0.0 removed the -p option. However, we reversed this decision in Facter 3.0.two and re-enabled the -p option. For details about latest and foreseeable future service for this option, see the Facter 3.0.two release notes .
Two parts of every fact
Setting aside external facts for now, most facts have at least two parts:
A call to Facter.increase('fact_name'). which determines the name of your fact
A setcode statement for effortless resolutions, which is evaluated to determine the fact’s value.
Facts can get a lot increased complicated than that, but those two together are one of the most standard implementation of the custom made fact.
Executing shell commands in facts
Puppet gets related information about a program from Facter, also, the most everyday way for Facter to get that material is by executing shell commands. You will then parse and manipulate the output from those commands making use of standard Ruby code. The Facter API gives you just a few ways to execute shell commands:
If all you need to do is run the command and make use of the output, verbatim, as your fact’s value, you’re able to pass the command into setcode directly. For example: setcode 'uname --hardware-platform'
If your fact is much more complicated than that, it's possible to call Facter::Core::Execution.exec('uname --hardware-platform') from in just the setcode do … finish block. As always, whatever the setcode statement returns is put to use given that the fact’s value.
In any case, remember that your shell command is likewise a Ruby string, so you’ll might need to escape special characters in the event you would like to pass them through.
It is important to note that not everything that is effective from the terminal will job in the fact . You’re able to make use of the pipe ( | ) and similar operators as you normally would, but Bash-specific syntax like if statements will not deliver the results. The perfect way to handle this limitation is to put in writing your conditional logic in Ruby.
Let’s say you require to get the output of uname --hardware-platform to one out a targeted type of workstation. To do this, you would form a new tailor made fact. Begin the process of by giving the fact a name, in this particular case, hardware_platform. and generate your new fact inside a file, hardware_platform.rb. about the Puppet master server:
You're able to then utilize the instructions within the Plugins in Modules web site to copy the new fact to some module and distribute it. During your next Puppet run, the value from the new fact will be around to make use of into your manifests and templates.
Employing other facts
You can still produce a fact that takes advantage of other facts by accessing Facter.value(:somefact). If the fact fails to resolve or is just not existing, Facter returns nil .
Configuring facts
Facts have one or two properties which you can use to customize how facts are evaluated.
Confining facts
A particular in the far more commonly made use of properties is the confine statement, which restricts the fact to only run on devices that matches another given fact.
An example belonging to the confine statement would be something like the following:
This fact makes use of sysfs on linux to get a list belonging to the power states that are obtainable relating to the given application. Since this is only in existence on Linux programs, we utilize the confine statement to ensure that this fact isn’t needlessly run on units that never help this type of enumeration.
Fact precedence
An individual fact can have many different resolutions . each individual of which is often a different way of ascertaining what the value belonging to the fact should be. It is very everyday to have different resolutions for different operating solutions, for example. It is trouble-free to confuse facts and resolutions mainly because they are superficially identical - to increase a new resolution to the fact, you simply increase the fact again, only accompanied by a different setcode statement.
When a fact has greater than a person resolution, the for starters resolution that returns a value other than nil will established the fact’s value. The way that Facter decides the issue of resolution precedence is the weight property. Once Facter rules out any resolutions that are excluded seeing that of confine statements, the resolution with the highest weight is evaluated for starters. If that resolution returns nil. Facter moves on to the next resolution (by descending weight) until it gets a value for your fact.
By default, the weight of the fact is the selection of confines for that resolution, so that significantly more special resolutions takes priority over less particular resolutions.
Execution timeouts
Facter two.x supported a :timeout option to Facter#add. Facter no longer supports this option, and produces a warning if it is second hand.
Although this version of Facter does not aid overall timeouts on resolutions, one can pass a timeout to Facter::Core::Execution#execute :
Structured facts
Whereas the norm is for a fact to return only one string, Facter two.0 introduced structured facts . which take the sort of either a hash or an array. All you absolutely need to do to make a structured fact is return a hash or an array from the setcode statement. It is easy to see some relevant examples during the crafting structured facts section belonging to the Fact Overview .
Aggregate resolutions
If your fact brings together the output of a few different commands, it may make perception to try aggregate resolutions . An aggregate resolution is split into “chunks”, each individual 1 responsible for resolving 1 piece with the fact. After all in the chunks have been resolved separately, they’re combined into one flat or structured fact and returned.
Aggregate resolutions have several key differences compared to easy resolutions, beginning with the fact declaration. To introduce an aggregate resolution, you’ll have to have to increase the :type => :aggregate parameter:
Each individual step while in the resolution then gets its have named chunk statement:
In a very rather simple resolution, the code always consists of a setcode statement that determines the fact’s value. Aggregate resolutions never have a setcode statement. Instead, they have an optional aggregate block that brings together the chunks. Whatever value the aggregate block returns will be the fact’s value. Here’s an example that just brings together the strings from the two chunks higher than:
If the chunk blocks either all return arrays or all return hashes, you can easlily omit the aggregate block. In the event you do, Facter robotically merges all of your knowledge into an individual array or hash and use that because the fact’s value.
For a lot more examples of aggregate resolutions, see the aggregate resolutions section for the Fact Overview web page.
Viewing fact values
If your Puppet master(s) are configured to make use of PuppetDB. you could watch and search all within the facts for any node, this includes tailor made facts. See the PuppetDB docs for much more info.
External facts
What are external facts?
External facts offer you a way make use of arbitrary executables or scripts as facts, or established facts statically with structured knowledge. If you’ve ever wanted to put in writing a custom made fact in Perl, C, or a one-line textual content file, this is how.
Fact locations
The recommended way to distribute external facts is with pluginsync, which extra assistance for them in Puppet 3.four /Facter two.0.1. To increase external facts to your Puppet modules, just destination them in <MODULEPATH>/<MODULE>/facts.d/ .
If you’re not by making use of pluginsync, then external facts must go in the standard directory. The location of this directory varies based upon your operating platform, whether your deployment utilizes Puppet Organization or open source releases, and whether you may be functioning as root/Administrator. When calling facter from the command line, it's possible to specify the external facts directory with the --external-dir option.
Note: These directories never necessarily exist by default; you may really want to build them. When you build the directory, make sure to restrict obtain so that only Administrators can be able to write to the directory.
In the module (recommended):
On Unix/Linux/OS X, there are three directories:
On Windows 2003:
When managing as a non-root / non-Administrator consumer:
Executable facts - Unix
Executable facts on Unix function by dropping an executable file into the standard external fact path previously mentioned. A shebang is always required for executable facts on Unix. If the shebang is missing, the execution belonging to the fact will fail.
An example external fact written in Python:
You must ensure that the script has its execute bit established:
For Facter to parse the output, the script must return key/value pairs on STDOUT during the format:
Choosing this format, just one script can return an array of facts.
Executable facts - Windows
Executable facts on Windows get the job done by dropping an executable file into the external fact path in your version of Windows. Unlike with Unix, the external facts interface expects Windows scripts to stop by having a known extension. Line endings is often either LF or CRLF. Within the moment the following extensions are supported:
.com and .exe. binary executables
.bat and .cmd. batch scripts
.ps1. PowerShell scripts
As with Unix facts, each individual script must return key/value pairs on STDOUT within the format:
Applying this format, just one script can return numerous facts in a single return.
Batch scripts
The file encoding for .bat/.cmd information must be ANSI or UTF8 without BOM (Byte Order Mark), otherwise you may get strange output.
Listed here is mostly a sample batch script which outputs facts utilising the required format:
PowerShell scripts
The encoding that should be put into use with .ps1 documents is pretty open. PowerShell determines the encoding for the file at run time.
Listed here is mostly a sample PowerShell script which outputs facts utilizing the required format:
You should be able to save and execute this PowerShell script about the command line.
Structured details facts
Facter can parse structured info information stored within the external facts directory and established facts according to their contents.
Structured information data files must use a particular in the supported facts varieties and must have the correct file extension. For the moment, Facter supports the following extensions and facts styles:
yaml. YAML info, within the following format:
json. JSON facts, during the following format:
txt. Key value pairs, inside the following format:
As with executable facts, structured information data files can established different facts at once.
Structured facts facts on Windows
All in the higher than variations are supported on Windows with the following caveats:
The line endings is either LF or CRLF .
The file encoding must be either ANSI or UTF8 without BOM (Byte Order Mark).
If your external fact is absolutely not appearing in Facter’s output, managing Facter in debug mode should give you a meaningful reason and tell you which file is causing the problem:
Just one example of when this could possibly happen is in cases where a fact returns invalid characters. Let say you utilized a hyphen instead of an equals sign in your own script :
Functioning puppet facts --debug should yield a useful message:
External facts and stdlib
Once you choose that an external fact does not match what you have configured with your facts.d directory, make sure you haven't defined the same fact by using the external facts abilities found from the stdlib module.
Whereas external facts provide you with a mostly-equal way to make variables for Puppet, they have one or two disadvantages:
An external fact cannot internally reference another fact. However, due to parse order, you’re able to reference an external fact from the Ruby fact.
External executable facts are forked instead of executed inside of the same system.
Distributing executable facts through pluginsync requires Puppet 3.four.0 or greater.
Facter 3.four do my essay online
deep cleaning
deep cleaning

le 22/10/2018 à 10:06

You can get a large number of benefits for everyone if you decide to hire store-bought cleaning small business. The service is over by industry professionals. You don't have to be mired by cleaning allowing it to do another fact with your energy and time. Your expenditure of money (office or house building) is without a doubt secured through commercial cleaners along with in-house service personnel or janitorial expertise. You would have a certainly clean and even well-sanitized office or house. The latter pores and skin look reason up to date, right? deep cleaning

Répondre à ce message

Vous n'êtes pas autorisé à poster un message sur le forum.