Créer un site internet

Prewriting and Outlining

  • DavidErabe
    DavidErabe

    le 01/08/2017 à 10:04 Citer ce message

    ?Customized facts walkthrough
    Custom made facts
    Lengthen Facter by creating your private custom made facts to furnish material to Puppet.
    Adding custom made facts to Facter
    Generally you may need to be able to write down conditional expressions determined by site-specific information that just isn’t attainable by means of Facter, or perhaps you’d like to include it in the template.
    Since you can’t include arbitrary Ruby code as part of your manifests, the most beneficial resolution is to increase a new fact to Facter. These more 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 options and replaced them along with a personalized facts API. Any custom made fact that requires just one within the Ruby information previously stored in lib/facter/util will fail with the error. For alot more info, see the Facter 3.0 release notes .
    The concept
    You'll insert new facts by creating snippets of Ruby code to the Puppet master. Puppet then employs Plugins in Modules to distribute the facts to the client.
    Loading custom made facts
    Facter delivers one or two methods of loading facts:
    $LOAD\_PATH. or the Ruby library load path
    The --custom-dir command line option.
    The environment variable ‘FACTERLIB’
    You might use these methods of loading facts to do things like take a look at documents locally before distributing them, otherwise you can arrange to have a special list of facts attainable on certain machines.
    Applying the Ruby load path
    Facter searches all directories inside of the Ruby $LOAD_PATH variable for subdirectories named ‘facter’, and loads all Ruby data files in those directories. At any time you had some directory with your $LOAD_PATH like
    /lib/ruby. create like this:
    Facter would try to load ‘facter/system_load.rb’, ‘facter/users.rb’, and ‘facter/rackspace.rb’.
    By using the --custom-dir command line option
    Facter can take several --custom-dir possibilities about the command line that specifies only one directory to search for tailor made facts. Facter attempts to load all Ruby documents while in the specified directories. This will allow for you to definitely do something like this:
    By means of 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 helps you to definitely do something like this:
    Note: Changes in built-in pluginsync assistance in Facter 3
    Facter two.four deprecated Facter’s service for loading facts by means 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 recent and long run guidance 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 features:
    A call to Facter.incorporate('fact_name'). which determines the name in the fact
    A setcode statement for straightforward 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 everyday implementation of the custom made fact.
    Executing shell commands in facts
    Puppet gets content about a platform from Facter, together with the most commonplace way for Facter to get that information and facts is by executing shell commands. You possibly can then parse and manipulate the output from those commands choosing standard Ruby code. The Facter API gives you a number of ways to execute shell commands:
    If all you must do is run the command and utilize the output, verbatim, as your fact’s value, you are able to pass the command into setcode directly. For example: setcode 'uname --hardware-platform'
    If your fact is extra complicated than that, it is easy to call Facter::Core::Execution.exec('uname --hardware-platform') from inside of the setcode do … conclude block. As always, whatever the setcode statement returns is chosen as being the fact’s value.
    In any case, remember that your shell command is additionally a Ruby string, so you’ll want to escape special characters any time you desire to pass them through.
    It is important to note that not everything that will work around the terminal will give good results inside of a fact . You'll utilize the pipe ( | ) and similar operators as you normally would, but Bash-specific syntax like if statements will not show results. The top rated way to handle this limitation is to jot down your conditional logic in Ruby.
    Example
    Let’s say you'll need to get the output of uname --hardware-platform to solitary out a certain type of workstation. To do this, you would establish a new personalized fact. Begin the process of by giving the fact a name, in such a case, hardware_platform. and set up your new fact in a very file, hardware_platform.rb. in the Puppet master server:
    You may then make use of 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 on the new fact will be on hand to employ within your manifests and templates.
    Utilising other facts
    You can easlily generate a fact that employs other facts by accessing Facter.value(:somefact). If the fact fails to resolve or shouldn't be current, Facter returns nil .
    Configuring facts
    Facts have several properties that you simply can use to customize how facts are evaluated.
    Confining facts
    Just one belonging to the a lot more commonly chosen properties is the confine statement, which restricts the fact to only run on solutions that matches another given fact.
    An example from the confine statement would be something like the following:
    This fact employs sysfs on linux to get a list for the power states that are out there in the given technique. Since this is only obtainable on Linux devices, we make use of the confine statement to ensure that this fact isn’t needlessly run on programs that never assist this type of enumeration.
    Fact precedence
    One fact can have several resolutions . every of which can be a different way of ascertaining what the value in the fact should be. It is very standard to have different resolutions for different operating methods, for example. It is simple and easy to confuse facts and resolutions considering they are superficially identical - to insert a new resolution to your fact, you simply include the fact again, only by using a different setcode statement.
    When a fact has even more than 1 resolution, the very first 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 due to the fact that of confine statements, the resolution with the highest weight is evaluated very first. If that resolution returns nil. Facter moves on to the next resolution (by descending weight) until it gets a value for that fact.
    By default, the weight of the fact is the variety of confines for that resolution, so that further certain resolutions takes priority over less unique 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 utilized.
    Although this version of Facter does not guidance overall timeouts on resolutions, you might pass a timeout to Facter::Core::Execution#execute :
    Structured facts
    As the norm is for a fact to return one string, Facter two.0 introduced structured facts . which take the kind of either a hash or an array. All you require to do to make a structured fact is return a hash or an array from the setcode statement. One can see some relevant examples on the creating structured facts section on the Fact Overview .
    Aggregate resolutions
    If your fact brings together the output of numerous commands, it may make perception to work with aggregate resolutions . An aggregate resolution is split into “chunks”, every a particular responsible for resolving 1 piece for the fact. After all with 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 uncomplicated resolutions, beginning with the fact declaration. To introduce an aggregate resolution, you’ll might need to increase the :type => :aggregate parameter:
    Each individual step while in the resolution then gets its have named chunk statement:
    Within a easy to understand resolution, the code always involves 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 earlier mentioned:
    If the chunk blocks either all return arrays or all return hashes, you will omit the aggregate block. For those who do, Facter quickly merges all of your info into a particular array or hash and use that because the fact’s value.
    For considerably more examples of aggregate resolutions, see the aggregate resolutions section within the Fact Overview web site.
    Viewing fact values
    If your Puppet master(s) are configured to try PuppetDB. you will see and search all belonging to the facts for any node, together with personalized facts. See the PuppetDB docs for even more info.
    External facts
    What are external facts?
    External facts offer you a way to apply arbitrary executables or scripts as facts, or established facts statically with structured facts. If you’ve ever wanted to jot down a tailor made fact in Perl, C, or a one-line textual content file, this is how.
    Fact locations
    The optimum way to distribute external facts is with pluginsync, which extra aid 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 utilising pluginsync, then external facts must go within a standard directory. The location of this directory varies according to your operating strategy, whether your deployment makes use of Puppet Business or open source releases, and whether you may be managing as root/Administrator. When calling facter from the command line, you are able to specify the external facts directory with the --external-dir option.
    Note: These directories really do not necessarily exist by default; you may need to get to make them. Once you construct the directory, make sure to restrict entry so that only Administrators can generate to the directory.
    In the module (recommended):
    On Unix/Linux/OS X, there are three directories:
    On Windows 2003:
    When working as a non-root / non-Administrator person:
    Executable facts - Unix
    Executable facts on Unix job by dropping an executable file into the standard external fact path over. A shebang is always required for executable facts on Unix. If the shebang is missing, the execution on 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 inside of the format:
    By means of this format, just one script can return an array of facts.
    Executable facts - Windows
    Executable facts on Windows perform by dropping an executable file into the external fact path for the version of Windows. Unlike with Unix, the external facts interface expects Windows scripts to close that has a known extension. Line endings are usually 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, every single script must return key/value pairs on STDOUT inside the format:
    By making use of this format, one script can return a variety of 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.
    Below is actually a sample batch script which outputs facts working with the required format:
    PowerShell scripts
    The encoding that should be applied with .ps1 data files is pretty open. PowerShell determines the encoding from the file at run time.
    Below could be a sample PowerShell script which outputs facts choosing the required format:
    You should be able to save and execute this PowerShell script in the command line.
    Structured knowledge facts
    Facter can parse structured facts information stored with the external facts directory and established facts dependant upon their contents.
    Structured info data files must use an individual from the supported info forms and must have the correct file extension. Within the moment, Facter supports the following extensions and info forms:
    yaml. YAML knowledge, on the following format:
    json. JSON information, inside following format:
    txt. Key value pairs, inside following format:
    As with executable facts, structured info documents can established an array of facts at once.
    Structured facts facts on Windows
    All of your higher than varieties are supported on Windows with the following caveats:
    The line endings could very well be either LF or CRLF .
    The file encoding must be either ANSI or UTF8 without BOM (Byte Order Mark).
    Troubleshooting
    If your external fact isn't 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:
    An individual example of when this might possibly happen is in cases where a fact returns invalid characters. Let say you employed a hyphen instead of an equals sign as part of your script exam.sh :
    Managing puppet facts --debug should yield a useful message:
    External facts and stdlib
    In the event you get that an external fact does not match what you have configured as part of your facts.d directory, make sure you haven't defined the same fact employing the external facts abilities found inside of the stdlib module.
    Negatives
    Even while external facts offer a mostly-equal way to generate variables for Puppet, they have two or three negatives:
    An external fact cannot internally reference another fact. However, due to parse order, you can still reference an external fact from the Ruby fact.
    External executable facts are forked instead of executed in the same procedure.
    Distributing executable facts through pluginsync requires Puppet 3.four.0 or greater.
    Facter 3.four solves math problems

Répondre à ce message