External Nodes
Version 18 (Mikael Fridh, 01/20/2012 04:04 pm)
| 1 | 3 | Ohad Levy | h1. Foreman can act as a classifier to Puppet through the external nodes interface. |
|---|---|---|---|
| 2 | 1 | ||
| 3 | 10 | Ohad Levy | You can now configure your hosts via a web interface, avoiding typing host specific information in your manifest. |
| 4 | 10 | Ohad Levy | |
| 5 | 4 | Ohad Levy | {{toc}} |
| 6 | 4 | Ohad Levy | |
| 7 | 2 | Ohad Levy | h2. Import your environment and classes setup |
| 8 | 1 | ||
| 9 | 11 | 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: |
| 10 | 1 | ||
| 11 | 1 | <pre> |
|
| 12 | 1 | rake puppet:import:puppet_classes RAILS_ENV=production |
|
| 13 | 1 | </pre> |
|
| 14 | 1 | ||
| 15 | 13 | Marcello de Sousa | If you get a prompt you might avoid it with the batch mode using: |
| 16 | 13 | Marcello de Sousa | <pre> |
| 17 | 13 | Marcello de Sousa | rake puppet:import:puppet_classes[batch] RAILS_ENV=production |
| 18 | 13 | Marcello de Sousa | </pre> |
| 19 | 13 | Marcello de Sousa | |
| 20 | 13 | Marcello de Sousa | |
| 21 | 1 | If you prefer, you may manually add classes through the setting page, however, the class names must match Puppet classes. |
|
| 22 | 1 | ||
| 23 | 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) |
| 24 | 12 | Ohad Levy | <pre>modulepath=/etc/puppet/modules</pre> |
| 25 | 1 | ||
| 26 | 2 | Ohad Levy | h2. Define classes and variables per host |
| 27 | 1 | ||
| 28 | 1 | You can define per host, classes and variables(parameters), simply create/edit a host, and select its classes. |
|
| 29 | 1 | if you see an empty list, make sure that you do have classes (as define in the step above). |
|
| 30 | 1 | ||
| 31 | 1 | If you want to add variables(parameters), simply add them in the same page as a set name and value. |
|
| 32 | 1 | ||
| 33 | 2 | Ohad Levy | h2. Host Groups |
| 34 | 1 | ||
| 35 | 3 | Ohad Levy | Foreman allows you to group classes, into common groups similar to node inheritances in puppet |
| 36 | 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). |
| 37 | 1 | ||
| 38 | 1 | If you wish to override the parameters for a specific host, create a parameter with the same name in the host level, |
|
| 39 | 3 | Ohad Levy | Foreman will override the values defined in the group level. |
| 40 | 1 | ||
| 41 | 1 | ||
| 42 | 2 | Ohad Levy | h2. Other places you can define parameters |
| 43 | 1 | ||
| 44 | 5 | Ohad Levy | It is also possible to define default (common) parameters for all of your hosts (setting -> Global parameters). |
| 45 | 15 | Ohad Levy | Additionally, you can also define them on the domain and operating system level (settings -> Domain -> Domain Parameters) |
| 46 | 1 | ||
| 47 | 1 | *The order in which the parameters are processed is: |
|
| 48 | 15 | Ohad Levy | Global, Domain, OS, Host Group and Node, the last occurrence of the parameter will be the one used. |
| 49 | 1 | * |
|
| 50 | 1 | ||
| 51 | 9 | Ohad Levy | h2. Example puppet external nodes script |
| 52 | 1 | ||
| 53 | 18 | Mikael Fridh | 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@. |
| 54 | 1 | ||
| 55 | 17 | Corey Osman | <pre> |
| 56 | 17 | Corey Osman | #! /usr/bin/ruby |
| 57 | 17 | Corey Osman | # a simple script which fetches external nodes from Foreman |
| 58 | 17 | Corey Osman | # you can basically use anything that knows how to get http data, e.g. wget/curl |
| 59 | 17 | Corey Osman | etc. |
| 60 | 17 | Corey Osman | |
| 61 | 17 | Corey Osman | # Foreman url |
| 62 | 17 | Corey Osman | foreman_url="http://foreman.sampledomain.corp" |
| 63 | 17 | Corey Osman | |
| 64 | 17 | Corey Osman | require 'net/http' |
| 65 | 17 | Corey Osman | |
| 66 | 17 | Corey Osman | foreman_url += "/node/#{ARGV[0]}?format=yml" |
| 67 | 17 | Corey Osman | url = URI.parse(foreman_url) |
| 68 | 17 | Corey Osman | req = Net::HTTP::Get.new(foreman_url) |
| 69 | 17 | Corey Osman | res = Net::HTTP.start(url.host, url.port) { |http| |
| 70 | 17 | Corey Osman | http.request(req) |
| 71 | 17 | Corey Osman | } |
| 72 | 17 | Corey Osman | |
| 73 | 17 | Corey Osman | case res |
| 74 | 17 | Corey Osman | when Net::HTTPOK |
| 75 | 17 | Corey Osman | puts res.body |
| 76 | 17 | Corey Osman | else |
| 77 | 17 | Corey Osman | $stderr.puts "Error retrieving node %s: %s" % [ARGV[0], res.class] |
| 78 | 17 | Corey Osman | end |
| 79 | 17 | Corey Osman | </pre> |
| 80 | 17 | Corey Osman | |
| 81 | 1 | You would need to setup puppet to use external nodes |
|
| 82 | 1 | <pre> external_nodes = /etc/puppet/node.rb |
|
| 83 | 1 | node_terminus = exec</pre> |
|
| 84 | 1 | For additional info please see "Puppet documentation":http://reductivelabs.com/trac/puppet/wiki/ExternalNodes |
|
| 85 | 1 | ||
| 86 | 1 | h2. Verify your setup |
|
| 87 | 1 | ||
| 88 | 1 | You may also click on the YAML link to see the output that would be used for puppet external nodes. |
|
| 89 | 8 | Ohad Levy | |
| 90 | 8 | Ohad Levy | h2. Import your external node setup from an older external node setup |
| 91 | 8 | Ohad Levy | |
| 92 | 8 | Ohad Levy | If you already had an external node setup, you can import your old setup directly to Foreman |
| 93 | 8 | Ohad Levy | |
| 94 | 8 | Ohad Levy | *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. |
| 95 | 8 | Ohad Levy | 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. |
| 96 | 8 | Ohad Levy | |
| 97 | 8 | Ohad Levy | 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). |
| 98 | 8 | Ohad Levy | |
| 99 | 8 | Ohad Levy | To import the classes and parameters per host, run: |
| 100 | 8 | Ohad Levy | |
| 101 | 8 | Ohad Levy | <pre> |
| 102 | 8 | Ohad Levy | rake puppet:import:external_nodes script=/path/to/old_external_node_script RAILS_ENV=production |
| 103 | 8 | Ohad Levy | </pre> |
| 104 | 8 | Ohad Levy | |
| 105 | 8 | Ohad Levy | |
| 106 | 8 | 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. |
