External Nodes » History » Revision 25
Revision 24 (Ohad Levy, 08/14/2012 03:48 AM) → Revision 25/30 (Sam Kottler, 10/04/2012 01:47 PM)
h1. Foreman can act as a classifier to Puppet through the external nodes interface.
You can now configure your hosts via a web interface, avoiding typing host specific information in your manifest.
{{toc}}
h2. Import your environment and classes setup
First of all, you probably want to let Foreman know about your setup, if you are using puppet modules - Foreman can import your setup automatically (environments and classes) by either:
h3. Importing via the WebUI
Simply goto either Environments or Classes page (under more) and click import.
Note that you would need a proxy server installed on at least one puppet master for this functionality.
h3. Importing via the CLI
<pre>
rake puppet:import:puppet_classes RAILS_ENV=production
</pre>
If you get a prompt you might avoid it with the batch mode using:
<pre>
rake puppet:import:puppet_classes[batch] RAILS_ENV=production
</pre>
If you prefer, you may manually add classes through the setting page, however, the class names must match Puppet classes.
if for some reason you can't see your nodes, please make sure that you have the following line in your puppet.conf file (or similar)
<pre>modulepath=/etc/puppet/modules</pre>
h2. Define classes and variables per host
You can define per host, classes and variables(parameters), simply create/edit a host, and select its classes.
if you see an empty list, make sure that you do have classes (as define in the step above).
If you want to add variables(parameters), simply add them in the same page as a set name and value.
h2. Host Groups
Foreman allows you to group classes, into common groups similar to node inheritances in puppet
Each group can contain many classes, variables, Provisioning information, and can even inherit from one another (You may think of them as templates for your hosts).
If you wish to override the parameters for a specific host, create a parameter with the same name in the host level,
Foreman will override the values defined in the group level.
h2. Other places you can define parameters
It is also possible to define default (common) parameters for all of your hosts (setting -> Global parameters).
Additionally, you can also define them on the domain and operating system level (settings -> Domain -> Domain Parameters)
*The order in which the parameters are processed is:
Global, Domain, OS, Host Group and Node, the last occurrence of the parameter will be the one used.
*
h2. Example puppet external nodes script
The example below is OLD and does not import facts, please look at the new ENC script example here: https://github.com/theforeman/puppet-foreman/blob/master/templates/external_node.rb.erb
You may find an example script under *extras/puppet/foreman/templates/external_node.rb.erb* - edit it and copy it to, for example: @/etc/puppet/node.rb@.
<pre>
#! /usr/bin/ruby
# a simple script which fetches external nodes from Foreman
# you can basically use anything that knows how to get http data, e.g. wget/curl
etc.
# Foreman url
foreman_url="http://foreman.sampledomain.corp"
require 'net/http'
require 'net/https' if foreman_url =~ /^https/
foreman_url += "/node/#{ARGV[0]}?format=yml"
url = URI.parse(foreman_url)
con = Net::HTTP.new(url.host, url.port)
con.use_ssl = (url.scheme == 'https')
req = Net::HTTP::Get.new(foreman_url)
res = con.start { |http| http.request(req) }
case res
when Net::HTTPOK
puts res.body
else
$stderr.puts "Error retrieving node %25s: %25s" %25 [ARGV[0], res.class]
end
</pre>
You would need to setup puppet to use external nodes
<pre> external_nodes = /etc/puppet/node.rb
node_terminus = exec</pre>
Make sure that the puppet user can execute your enc script and it works:
<pre>
sudo su - puppet -s /bin/bash
/etc/puppet/node.rb [the name of a node, eg agent.local]
</pre>
should output something like:
<pre>
parameters:
puppetmaster: puppet
foreman_env: &id001 production
root_pw: xybxa6JUkz63w
classes:
- helloworld
environment: *id001
</pre>
For additional info please see "Puppet documentation":http://reductivelabs.com/trac/puppet/wiki/ExternalNodes
h2. Verify your setup
You may also click on the YAML link to see the output that would be used for puppet external nodes.
h2. Import your external node setup from an older external node setup
If you already had an external node setup, you can import your old setup directly to Foreman
*Note*: This will import your classes and variables (parameters or tags) directly, that means that if you have any logic to dynamically generate the variables, it would not be imported.
However, if you define your parameters in the domain level (for example) they will not be added to every single host, therefor, if you want to apply certain parameters per domain, host class etc, you should define them prior to running the importer.
additionally, it will not import any invalid settings, e.g. parameters which has the same name as facts, or a non string parameters (some classifiers tend to create those).
To import the classes and parameters per host, run:
<pre>
rake puppet:import:external_nodes script=/path/to/old_external_node_script RAILS_ENV=production
</pre>
*Note*: This will only scan for hosts that already exists in our database, if you want to import hosts, use one of the other importers.