Puppet::Orchestrator - Connects to the Puppet Orchestrator API (i.e. Puppet Tasks)
version 0.002
This module interacts with the Puppet Orchestrator API (i.e. Puppet Tasks)
use Puppet::DB; use Puppet::Orchestrator; use Puppet::Classify; # Create a Puppet DB object my $puppet_db = Puppet::DB->new( server_name => $config->{puppetdb_host}, server_port => $config->{puppetdb_port}, ); # Create a Puppet classification object my $classify = Puppet::Classify->new( cert_name => $config->{puppet_classify_cert}, server_name => $config->{puppet_classify_host}, server_port => $config->{puppet_classify_port}, puppet_ssl_path => $config->{puppet_ssl_path}, puppet_db => $puppet_db, ); # Create a Puppet orchestrator object my $orchestrator = Puppet::Orchestrator->new( cert_name => $config->{puppet_orch_cert}, server_name => $config->{puppet_orch_host}, server_port => $config->{puppet_orch_port}, puppet_ssl_path => $config->{puppet_ssl_path}, puppet_db => $puppet_db, ); $group = "All Nodes"; my $nodes = $classify->get_nodes_matching_group( $group ); my $jobid = $orchestrator->submit_task( "profile::check_id", { "id" => "836" }, $nodes ); $orchestrator->print_output_wait($jobid);
It requires the Puppet::DB module. The Puppet::Classify is recommended as it allows looking up group membership.
The puppet master that is running the Orchestrator API. Connects to localhost by default.
$orchestrator->server_name('puppet.example.com');
Connect to the Puppet Orchestrator server on port 8143 by default - this can be overidden when consumed.
$orchestrator->server_port(8754);
Use an access_token instead of a certificate to connect to the API. This loads the authentication token saved in your home, but it can be set manually if it is not stored there.
say $orchestrator->access_token;
The environment to look in for the task to be run - this can be overidden when consumed. Defaults to 'production'.
$orchestrator->environment('test');
the basename of the certificate to be used for authentication. This is a certificate that has been generated on the Puppet Master and added to the whitelist. This can be used instead of using an auth token.
$orchestrator->cert_name('api_access');
Set the path to the Puppet SSL certs, it uses the Puppet enterprise path by default.
The connection timeout. Defaults to 360 seconds.
$orchestrator->timeout(30);
The puppet DB object used to interact with the Puppet DB.
$orchestrator->puppet_db(Puppet::DB->new);
A list of nodes to perform the task on
my $nodes = [ qw( node1 node2 ) ]; $orchestrator->nodes($nodes);
The job ID number
say $orchestrator->job_id;
This method sleeps until the job is finished or the timeout in seconds is reached. The timeout is optional, if not specified, it will sleep indefinately.
$orchestrator->wait_for_job( $jobid, $timeout );
Submit a new task
my $task_name = "package", my $params = { action => "install", name => "httpd", } my $nodes = [ qw( node1 node2 ) ]; my $jobid = $orchestrator->submit_task( $task_name, $params, $nodes ); my $timeout = 20; $orchestrator->wait_for_job( $jobid, $timeout );
Simply returns true or false based on whether the job is finished
say "Done" if $is_job_finished->job_id;
This will print the job output as it becomes available and wait until the job is finished.
$orchestrator->print_output_wait;
Matthew Mallard <mqtech@cpan.org>
This software is copyright (c) 2019 by Matthew Mallard.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Puppet::Orchestrator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Puppet::Orchestrator
CPAN shell
perl -MCPAN -e shell install Puppet::Orchestrator
For more information on module installation, please visit the detailed CPAN module installation guide.