Project

General

Profile

External Nodes » History » Version 27

Greg Sutcliffe, 10/04/2012 02:01 PM

1 3 Ohad Levy
h1. Foreman can act as a classifier to Puppet through the external nodes interface.
2 1 Ohad Levy
3 10 Ohad Levy
You can now configure your hosts via a web interface, avoiding typing host specific information in your manifest.
4
5 4 Ohad Levy
{{toc}}
6
7 2 Ohad Levy
h2. Import your environment and classes setup
8 1 Ohad Levy
9 24 Ohad Levy
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:
10
11
h3. Importing via the WebUI
12
13
Simply goto either Environments or Classes page (under more) and click import.
14
Note that you would need a proxy server installed on at least one puppet master for this functionality.
15
16
h3. Importing via the CLI
17 1 Ohad Levy
18
<pre>
19
rake puppet:import:puppet_classes RAILS_ENV=production
20
</pre>
21
22 13 Marcello de Sousa
If you get a prompt you might avoid it with the batch mode using:
23
<pre>
24
rake puppet:import:puppet_classes[batch] RAILS_ENV=production
25
</pre>
26
27
28 1 Ohad Levy
If you prefer, you may manually add classes through the setting page, however, the class names must match Puppet classes.
29
30 14 keith obrien
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)
31 12 Ohad Levy
<pre>modulepath=/etc/puppet/modules</pre> 
32 1 Ohad Levy
33 2 Ohad Levy
h2. Define classes and variables per host
34 1 Ohad Levy
35
You can define per host, classes and variables(parameters), simply create/edit a host, and select its classes.
36
if you see an empty list, make sure that you do have classes (as define in the step above).
37
38
If you want to add variables(parameters), simply add them in the same page as a set name and value.
39
40 2 Ohad Levy
h2. Host Groups
41 1 Ohad Levy
42 3 Ohad Levy
Foreman allows you to group classes, into common groups similar to node inheritances in puppet 
43 16 Ohad Levy
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).
44 1 Ohad Levy
45
If you wish to override the parameters for a specific host, create a parameter with the same name in the host level, 
46 3 Ohad Levy
Foreman will override the values defined in the group level.
47 1 Ohad Levy
48
49 2 Ohad Levy
h2. Other places you can define parameters
50 1 Ohad Levy
51 5 Ohad Levy
It is also possible to define default (common) parameters for all of your hosts (setting -> Global parameters).
52 15 Ohad Levy
Additionally, you can also define them on the domain and operating system level (settings -> Domain -> Domain Parameters)
53 1 Ohad Levy
54
*The order in which the parameters are processed is:
55 15 Ohad Levy
Global, Domain, OS, Host Group and Node, the last occurrence of the parameter will be the one used.
56 1 Ohad Levy
*
57
58 9 Ohad Levy
h2. Example puppet external nodes script
59 1 Ohad Levy
60 27 Greg Sutcliffe
You may find an example script under *extras/puppet/foreman/templates/external_node.rb.erb* - this is now outdated and *should not be used*
61 1 Ohad Levy
62 27 Greg Sutcliffe
The new ENC script example is here: https://github.com/theforeman/puppet-foreman/blob/master/templates/external_node.rb.erb - edit it and copy it to, for example: @/etc/puppet/node.rb@.
63
64 26 Greg Sutcliffe
You will need to edit the four variables at the top of the template:
65
66
<pre>
67
  :url          => "<%25= @foreman_url %25>",
68
  :puppetdir    => "<%25= @puppet_home %25>",
69
  :facts        => <%25= @facts %25>,
70
  :storeconfigs => <%25= @storeconfigs %25>,
71
</pre>
72
73
These are:
74
* :url [string] - the full URL of your foreman server, eg 'http://myforeman.domain:3000'
75
* :puppetdir [string] - where the vardir of your puppet installation is - usually '/var/lib/puppet'
76
* :facts [boolean] - do you want to upload facts from the clients to Foreman? If so, make this _true_, if not _false_
77
* :storeconfigs [boolean] - if you are sharing puppet's storeconfig database with Foreman, make this _true_, otherwise _false_
78
79
so a completed block might look like:
80
81
<pre>
82
  :url          => "http://foreman.example.org",
83
  :puppetdir    => "/var/lib/puppet",
84
  :facts        => true,
85 23 Brian Gupta
  :storeconfigs => false,
86 18 Mikael Fridh
</pre>
87 1 Ohad Levy
88
You would need to setup puppet to use external nodes 
89
<pre>  external_nodes = /etc/puppet/node.rb
90 21 Lloyd Fournier
  node_terminus  = exec</pre>
91
92 22 Lloyd Fournier
Make sure that the puppet user can execute your enc script and it works:
93 21 Lloyd Fournier
<pre>
94
sudo su - puppet -s /bin/bash
95
/etc/puppet/node.rb [the name of a node, eg agent.local]
96
</pre>
97
98
should output something like:
99
<pre>
100
  parameters: 
101
    puppetmaster: puppet
102
    foreman_env: &id001 production
103
    root_pw: xybxa6JUkz63w
104
  classes: 
105
    - helloworld
106
  environment: *id001
107
</pre>
108
109 1 Ohad Levy
For additional info please see "Puppet documentation":http://reductivelabs.com/trac/puppet/wiki/ExternalNodes
110
111
h2. Verify your setup
112
113 8 Ohad Levy
You may also click on the YAML link to see the output that would be used for puppet external nodes.
114
115
h2. Import your external node setup from an older external node setup
116
117
If you already had an external node setup, you can import your old setup directly to Foreman
118
119
*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.
120
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.
121
122
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).
123
124
To import the classes and parameters per host, run:
125
126
<pre>
127
rake puppet:import:external_nodes script=/path/to/old_external_node_script RAILS_ENV=production
128
</pre>
129
130
131 1 Ohad Levy
*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.