Module to access hosts from foreman
Switch branches/tags
Clone or download
Failed to load latest commit information.
.gitignore initial commit Jan 28, 2015
README.pod updated readme Jan 21, 2016 test modify host Jun 20, 2016 fix to prevent crash if storeable data is corrupt Aug 16, 2017
meta.yml prepared for publishing Jun 19, 2015



Foreman - Read host information out of Foreman.

With this module you can retrieve hosts and host parameter from Foreman. You can create dynamic groups out of these hosts.


use Foreman;

my $foreman = Foreman->new(
  url      => "https://foreman.your-domain.tld",
  user     => "foreman-user",
  password => "foreman-password",

group frontends => $foreman->get_hosts(environment => "stage", service => "shop");



The get_hosts() method will construct a search query with the given key => value parameters and send it to foreman. The returning data will be converted in an array. Every Array-Item is an object of the type Foreman::Server. This object can just be passed on to the group() function.

If you store the authentication settings inside Foreman you can modify these data inside the Foreman::Server object so that Rex knows which login and password to use.

my $foreman = Foreman->new(
  url      => "https://foreman.your-domain.tld",
  user     => "foreman-user",
  password => "foreman-password",
  modify_host_options => sub {
   my ($foreman, $server) = @_;
   $server->{auth}->{user}      = $server->{deploy_user};
   $server->{auth}->{password}  = decrypt($server->{deploy_password});
   $server->{auth}->{auth_type} = $server->{auth_type};
get_host(host => "hostname")

This method will return a single host object (Foreman::Server).


This method will return all environments Foreman is aware of. It will return a list of names.


This method will return a list of roles Foreman knows (for example Puppet roles). In fact this method is querying Foreman for all known puppetclasses and return the ones which start with role_.

get_hostgroup_parameters(hostgroup => "hostgroup-name")

This method will return all parameters that are registered with a hostgroup.

get_host_parameters(host => "hostname")

This method will return all host parameters that are registered with a host. It will also merge the hostgroup parameters.


Copyright 2015 FILIADATA GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.