Query Interface
Version 11 (Ohad Levy, 11/17/2011 09:37 am)
| 1 | 1 | h1. Query Interface |
|
|---|---|---|---|
| 2 | 1 | ||
| 3 | 6 | Ohad Levy | *Note*: you need to use Foreman 0.1-3 or latest git version for this feature. |
| 4 | 11 | Ohad Levy | *Note*: This feature will be *DEPRECATED* in the future and replace by the [[Search API]]. |
| 5 | 6 | Ohad Levy | |
| 6 | 7 | Ohad Levy | It's possible to use Foreman database to feed other applications - e.g. ssh or use it for cmdb like operations |
| 7 | 2 | Ohad Levy | |
| 8 | 1 | h2. Provide host list based on facts and classes |
|
| 9 | 1 | ||
| 10 | 1 | in the source:extras/query directory you could find an example multi ssh script providing example of how to run a command on all of your hosts that answer a certain criteria. |
|
| 11 | 1 | ||
| 12 | 1 | an additional ruby library (source:extras/query/foreman.rb) is available to write your own scripts. |
|
| 13 | 5 | Ohad Levy | |
| 14 | 1 | in any case, make sure that you edit foreman.rb to point to your foreman installations (defaults to http://foreman:3000). |
|
| 15 | 5 | Ohad Levy | |
| 16 | 6 | Ohad Levy | h3. Example Script |
| 17 | 4 | Ohad Levy | |
| 18 | 6 | Ohad Levy | <pre> |
| 19 | 4 | Ohad Levy | Usage: ./ssh_using_foreman |
| 20 | 4 | Ohad Levy | execute commands on multiple hosts |
| 21 | 4 | Ohad Levy | Query Foreman to provide host list based on collections of facts and classes |
| 22 | 4 | Ohad Levy | |
| 23 | 4 | Ohad Levy | -c, --command CMD command to execute |
| 24 | 4 | Ohad Levy | -u, --user USER User to use - defaults to root |
| 25 | 4 | Ohad Levy | -f, --facts fact=x,fact=y.. one or more facts to filter the host list |
| 26 | 4 | Ohad Levy | -p, --puppetclass CLASSA,CLASSB one or more classes to filter the host list |
| 27 | 8 | Ohad Levy | -s, --state STATE Filter base of host state - active,out_of_sync all defaults to active hosts |
| 28 | 4 | Ohad Levy | -h, --help Display this screen |
| 29 | 4 | Ohad Levy | </pre> |
| 30 | 4 | Ohad Levy | |
| 31 | 4 | Ohad Levy | |
| 32 | 4 | Ohad Levy | <pre> |
| 33 | 4 | Ohad Levy | ssh_using_foreman -c 'uname -i' -f operatingsystem=RedHat,operatingsystemrelease=5 |
| 34 | 4 | Ohad Levy | About to execute: uname -i |
| 35 | 4 | Ohad Levy | on the following 36 hosts: sublalic01.sub.domain subla003.sub.domain sublc005.sub.domain subla001.sub.domain sublakiew048.sub.domain subla001.sub.domain subla077.sub.domain subla124.sub.domain subla002.sub.domain subla033.sub.domain lnzla001.lnz.domain sublav04.sub.domain sublav05.sub.domain subla006.sub.domain subla114.sub.domain subla113.sub.domain subla141.sub.domain subla109.sub.domain sublav03.sub.domain subla005.sub.domain subla001.sub.domain sublc084.sub.domain subla011.sub.domain subla002.sub.domain subla030.sub.domain subla001.sub.domain subla001.sub.domain subla002.sub.domain subla004.sub.domain subla003.sub.domain subla004.sub.domain subla015.sub.domain sublcelba40.sub.domain sublcelba41.sub.domain subla008.sub.domain sublc090.sub.domain |
| 36 | 4 | Ohad Levy | ctrl-c to abort or any key to continue |
| 37 | 4 | Ohad Levy | |
| 38 | 4 | Ohad Levy | error connecting to root@subla015.sub.domain: Net::SSH::AuthenticationFailed (root@subla015.sub.domain) |
| 39 | 4 | Ohad Levy | error connecting to root@subla008.sub.domain: Net::SSH::AuthenticationFailed (root@subla008.sub.domain) |
| 40 | 4 | Ohad Levy | [subla077.sub.domain] x86_64 |
| 41 | 4 | Ohad Levy | [subla124.sub.domain] x86_64 |
| 42 | 4 | Ohad Levy | [subla001.sub.domain] i386 |
| 43 | 4 | Ohad Levy | [subla002.sub.domain] i386 |
| 44 | 4 | Ohad Levy | [sublc090.sub.domain] x86_64 |
| 45 | 4 | Ohad Levy | [subla003.sub.domain] i386 |
| 46 | 4 | Ohad Levy | [subla001.sub.domain] i386 |
| 47 | 4 | Ohad Levy | [subla002.sub.domain] x86_64 |
| 48 | 4 | Ohad Levy | [subla004.sub.domain] i386 |
| 49 | 4 | Ohad Levy | [subla001.sub.domain] i386 |
| 50 | 4 | Ohad Levy | [sublc084.sub.domain] x86_64 |
| 51 | 4 | Ohad Levy | [subla030.sub.domain] i386 |
| 52 | 4 | Ohad Levy | [subla003.sub.domain] x86_64 |
| 53 | 4 | Ohad Levy | [sublc005.sub.domain] x86_64 |
| 54 | 4 | Ohad Levy | [subla001.sub.domain] i386 |
| 55 | 4 | Ohad Levy | [sublakiew048.sub.domain] i386 |
| 56 | 4 | Ohad Levy | [subla006.sub.domain] i386 |
| 57 | 4 | Ohad Levy | [subla114.sub.domain] x86_64 |
| 58 | 4 | Ohad Levy | [sublav03.sub.domain] x86_64 |
| 59 | 4 | Ohad Levy | [subla005.sub.domain] i386 |
| 60 | 4 | Ohad Levy | [subla001.sub.domain] i386 |
| 61 | 4 | Ohad Levy | [sublcelba41.sub.domain] x86_64 |
| 62 | 4 | Ohad Levy | [sublalic01.sub.domain] x86_64 |
| 63 | 4 | Ohad Levy | [subla033.sub.domain] x86_64 |
| 64 | 4 | Ohad Levy | [lnzla001.lnz.domain] i386 |
| 65 | 4 | Ohad Levy | |
| 66 | 4 | Ohad Levy | </pre> |
| 67 | 4 | Ohad Levy | |
| 68 | 4 | Ohad Levy | |
| 69 | 1 | h2. Fetch the host list from a puppet manifest / template |
|
| 70 | 1 | ||
| 71 | 9 | Ohad Levy | see example puppet foreman module - it includes a "custom puppet function":http://github.com/ohadlevy/puppet-foreman/blob/master/foreman/plugins/puppet/parser/functions/foreman.rb |
