moose-inventory 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7a05c05e173698bcbc3b5bcce29ea2c0c7c3bd
4
- data.tar.gz: ea46d916c9a5776ce8e3119821ef009fea2e7d4a
3
+ metadata.gz: 5b88c60df4ba175770a974076cf92e3c1c130d1e
4
+ data.tar.gz: d7c7481e41f66ff8ea49ed8e64593d3221eb3fcf
5
5
  SHA512:
6
- metadata.gz: 3437c73ddf392819163040737720441e436a86714d4a682f0d5013e7799668ab19533bd1610d9f25b1d5a8c01dd0b8df77b49d4a9accd13b227e4312602848a3
7
- data.tar.gz: f405d9fbc5c6f7415abf9cc0f96762a96c50d0439971be527faee5918d89cce9bc099fc0173c7c7fcae8f83a5e587203353b63e687f3cf1ec35062c83cf3b68b
6
+ metadata.gz: f3447e95438f00cfbcfb9c14553c5fd68cad6c9d263f4eb00d2f9e61498fd8139d6dff4a6401480d384e5e91e4fc655f9f674582080eff77fd671da6245e16b0
7
+ data.tar.gz: 5bf036761787ba2ea318dd65f0462d5dffaa7e36bbf63cb0e451c39b7b7e77fc2567adbcb0a4937569469bef5600123b6d2f52c7879909a45abfc5570dc06128
data/README.md CHANGED
@@ -1,27 +1,21 @@
1
1
  # moose-inventory
2
2
 
3
- The [moose-inventory](https://github.com/RusDavies/moose-inventory) Ruby Gem is a package for managing dynamic inventories, intended for use with [Ansible](http://www.ansible.com/home).
3
+ The [moose-inventory](https://github.com/RusDavies/moose-inventory) software is a tool for managing dynamic inventories, intended for use with [Ansible](http://www.ansible.com/home).
4
4
 
5
5
  Note: This software is intended for use on UNIX, Linux, or similar systems. It will likely not work on Windows, due to some hard-wired search paths - I may fix that in the future but, for now, sorry.
6
6
 
7
7
  ## Installation
8
8
 
9
- The tool is a ruby gem.
10
-
11
- It can be install from the command line as follows.
9
+ The tool is a ruby gem. Assuming that you have ruby on your system, then it can be installed from the command line as follows.
12
10
 
13
11
  $ gem install moose-inventory
14
12
 
15
- Alternatively, it can be installed by adding the following line to a Gemfile:
13
+ It can also be installed by adding the following line to a Gemfile and then executing `bundle`:
16
14
 
17
15
  ```ruby
18
16
  gem 'moose-inventory'
19
17
  ```
20
18
 
21
- And then executing:
22
-
23
- $ bundle
24
-
25
19
 
26
20
  ## Configuration
27
21
  The [moose-inventory](https://github.com/RusDavies/moose-inventory) tool makes use of a simple YAML configuration file.
@@ -31,14 +25,14 @@ The [moose-inventory](https://github.com/RusDavies/moose-inventory) tool makes u
31
25
 
32
26
  The following locations, in descending order of precedence, are searched for a configuration file:
33
27
 
34
- 1. location passed via the *-<sp>-config* CLI option
28
+ 1. location passed via the `--config` option
35
29
  2. ./.moose-tools/inventory/config
36
30
  4. ~/.moose-tools/inventory/config
37
31
  5. ~/local/etc/moose-tools/inventory/config
38
32
  6. /etc/moose-tools/inventory/config
39
33
 
40
34
  ###Format
41
- The file consists of a mandatory *general* section, and at least one environment section. For example:
35
+ The file consists of a mandatory *general* section, and at least one *environment* section. For example:
42
36
  ```yaml
43
37
  ---
44
38
  general:
@@ -84,32 +78,32 @@ Additional parameters are also required in the **db** subsection, depending on t
84
78
  ### The help system
85
79
  The tool itself provides a convenient help feature. For example, try each of the following,
86
80
 
87
- > moose-inventory help
88
- > moose-inventory help group
89
- > moose-inventory group help add
81
+ $ moose-inventory help
82
+ $ moose-inventory help group
83
+ $ moose-inventory group help add
90
84
 
91
85
  ###Global switches
92
86
 
93
87
  #### Option `--config <FILE>`
94
- The *--config* flag sets the configuration file to be used. If specified, then the file must exist. This takes precedence over all other config files in other locations. If not provided, then the default is to search standard locations, see later.
88
+ The `--config` flag sets the configuration file to be used. If specified, then the file must exist. This takes precedence over all other config files in other locations. If not provided, then the default is to search the locations previously mentioned.
95
89
 
96
90
  For example,
97
91
 
98
- > moose-inventory --config ./my_conf host list
92
+ $ moose-inventory --config ./mystuff.conf host list
99
93
 
100
94
  #### Option `--env <SECTION>`
101
- The *--env* flag sets the section in the configuration file to be used as the environment configuration. If set, then the section must exist. If not set, then what ever default is provided in the general::defaultenv parameter of the configuration file will be used.
95
+ The *--env* flag sets the section in the configuration file to be used as the environment configuration. If set, then the section must exist. If not set, then what ever default is provided by the **defaultenv** parameter will be used.
102
96
 
103
97
  For example,
104
98
 
105
- > moose-inventory --env my_section host list
99
+ $ moose-inventory --env my_section host list
106
100
 
107
101
  #### Option `--format <yaml|json|pjson>`
108
- The *--format* switch changes the output format from *list* and *get* operations. Valid formats are yaml, json, pjson (i.e. pretty JSON). If the switch is not given, then the default is json.
102
+ The `--format` switch changes the output format for *list* and *get* operations. Valid formats are yaml, json, pjson (i.e. pretty JSON). If the switch is not given, then the default is json.
109
103
 
110
104
  For example,
111
105
 
112
- > moose-inventory --format yaml host list
106
+ $ moose-inventory --format yaml host list
113
107
  ---
114
108
  :test1:
115
109
  :groups:
@@ -118,12 +112,12 @@ For example,
118
112
  ###Transactional Behaviour
119
113
  The *moose-inventory* tool performs database operations in a transactional manner. That is to say, either all operations of a command succeed, or they are all rolled back.
120
114
 
121
- ###Walk-through examples
115
+ ###Walk-through example
122
116
  This walk-through goes through the process of creating three hosts and three groups, assigning variables to some of each, and then associating hosts with groups. Once done, each association, variable, group, and host are removed.
123
117
 
124
118
  We start by creating three hosts, in this case named *host1*, *host2*, and *host3*. Note, we can add as many hosts as we desire via this single command. Also, although we have used short names here, we could equally have used fully qualified names.
125
119
 
126
- > moose-inventory add host host1 host2 host3
120
+ $ moose-inventory add host host1 host2 host3
127
121
  Add host 'host1':
128
122
  - creating host 'host1'...
129
123
  - OK
@@ -148,7 +142,7 @@ Notice that each host is initially associated with an automatic group, *ungroupe
148
142
 
149
143
  Now we can list our hosts, to see that they are stored as expected. In this example, we will request the output be formatted as YAML. If we didn't specify a format, then it would default to regular JSON.
150
144
 
151
- > moose-inventory host list --format pjson
145
+ $ moose-inventory host list --format pjson
152
146
  {
153
147
  "host1": {
154
148
  "groups": [
@@ -169,7 +163,7 @@ Now we can list our hosts, to see that they are stored as expected. In this exa
169
163
 
170
164
  The *host list* command simply lists all hosts, in the order that they were entered into the database. We can also get a specific host, or hosts, by name. In this example, we'll get only *host3* and *host1*, outputting the result in YAML.
171
165
 
172
- > moose-inventory host get host3 host1 --format yaml
166
+ $ moose-inventory host get host3 host1 --format yaml
173
167
  ---
174
168
  :host3:
175
169
  :groups:
@@ -180,7 +174,7 @@ The *host list* command simply lists all hosts, in the order that they were ente
180
174
 
181
175
  Now we'll add some host variables. Again, we can add as many variables to a host as we desire.
182
176
 
183
- > moose-inventory host addvar host1 owner=russell id=12345
177
+ $ moose-inventory host addvar host1 owner=russell id=12345
184
178
  Add variables 'owner=russell,id=12345' to host 'host1':
185
179
  - retrieve host 'host1'...
186
180
  - OK
@@ -191,7 +185,7 @@ Now we'll add some host variables. Again, we can add as many variables to a hos
191
185
  - all OK
192
186
  Succeeded.
193
187
 
194
- > moose-inventory host addvar host2 owner=caroline id=54321
188
+ $ moose-inventory host addvar host2 owner=caroline id=54321
195
189
  Add variables 'owner=caroline,id=54321' to host 'host2':
196
190
  - retrieve host 'host2'...
197
191
  - OK
@@ -204,7 +198,7 @@ Now we'll add some host variables. Again, we can add as many variables to a hos
204
198
 
205
199
  Let's list our hosts again, to see what that looks like.
206
200
 
207
- > moose-inventory host list --format yaml
201
+ $ moose-inventory host list --format yaml
208
202
  ---
209
203
  :host1:
210
204
  :groups:
@@ -226,15 +220,15 @@ As you can see, the hosts with variables each have a new section, hostvars, in w
226
220
 
227
221
  We can do the same with groups. In the following example, the output has been omitted for compactness. Nevertheless, you will see that the form of the commands is as for hosts. Of note, when listing the groups, you will see that the *ungrouped* group is shown. This is an automatic group which cannot be manipulated manually.
228
222
 
229
- > moose-inventory group add group1 group2 group3
230
- > moose-inventory group list --format yaml
231
- > moose-inventory group get ungrouped group2 --format yaml
232
- > moose-inventory group addvar group1 location=usa
233
- > moose-inventory group addvar group2 location=europe
223
+ $ moose-inventory group add group1 group2 group3
224
+ $ moose-inventory group list --format yaml
225
+ $ moose-inventory group get ungrouped group2 --format yaml
226
+ $ moose-inventory group addvar group1 location=usa
227
+ $ moose-inventory group addvar group2 location=europe
234
228
 
235
229
  At this point, we have three hosts and three groups, some of each with variables. Let's now associate hosts with groups. We can either associate one or more hosts with a group,
236
230
 
237
- > moose-inventory group addhost group1 host1 host2
231
+ $ moose-inventory group addhost group1 host1 host2
238
232
  Associate group 'group1' with host(s) 'host1,host2':
239
233
  - retrieve group 'group1'...
240
234
  - OK
@@ -251,7 +245,7 @@ At this point, we have three hosts and three groups, some of each with variables
251
245
 
252
246
  or one or more groups with a host,
253
247
 
254
- > moose-inventory host addgroup host3 group2 group3
248
+ $ moose-inventory host addgroup host3 group2 group3
255
249
  Associate host 'host3' with groups 'group2,group3':
256
250
  - Retrieve host 'host3'...
257
251
  - OK
@@ -266,7 +260,7 @@ or one or more groups with a host,
266
260
 
267
261
  Notice in each of the two above excepts, the group *ungrouped* is automatically removed from each host, as it gains one or more group associations. Now we can again list our groups, to see what we have.
268
262
 
269
- > moose-inventory group list --format yaml
263
+ $ moose-inventory group list --format yaml
270
264
  ---
271
265
  :ungrouped: {}
272
266
  :group1:
@@ -304,13 +298,14 @@ We can also list hosts, to get the host-centric view.
304
298
 
305
299
  Removing variables, groups, and hosts is just as easy. In the following examples, the output is again omitted for compactness; the reader is encouraged to work along to experience the tool. Note, that although we show how to remove the variables, it is not strictly necessary to do so in this example, since deleting hosts and groups would delete all associated variables anyway.
306
300
 
307
- > moose-inventory group rmvar group1 location
308
- > moose-inventory group rm group1 group2 group3
309
- > moose-inventory host rmvar
310
- > moose-inventory host rmvar host1 owner id
311
- > moose-inventory host rm host1 host2 host3
301
+ $ moose-inventory group rmvar group1 location
302
+ $ moose-inventory group rm group1 group2 group3
303
+ $ moose-inventory host rmvar
304
+ $ moose-inventory host rmvar host1 owner id
305
+ $ moose-inventory host rm host1 host2 host3
312
306
 
313
307
  ### Using moose-inventory with Ansible
308
+
314
309
  The *moose-inventory* tool is compliant with the Ansible specifications for [dynamic inventory sources](http://docs.ansible.com/developing_inventory.html).
315
310
 
316
311
  However, to make use of *moose-inventory's* multiple environment and configuration file options, a shim script should be used as the target for the [external inventory script](http://docs.ansible.com/intro_dynamic_inventory.html). A trivial example may look something like this,
@@ -325,25 +320,34 @@ moose-inventory --config $CONF --env $ENV $@
325
320
 
326
321
  exit $?
327
322
  ```
328
- When Ansible calls the external inventory script, it does so using certain parameters, which *moose-inventory* automatically recognises and responds to. The Ansible parameters, and their equivalent *moose-inventory* parameters are shown below.
323
+ When Ansible calls the external inventory script, it passes certain parameters, which *moose-inventory* automatically recognises and responds to. The Ansible parameters, and their equivalent *moose-inventory* parameters are shown below.
329
324
 
330
325
  Ansible | moose-inventory
331
326
  ---------------- |-------------
332
327
  `--list` | `--ansible group list`
333
328
  `--host HOSTNAME` | `--ansible host listvars HOSTNAME`
334
329
 
335
- Note, the above conversions are done **automatically** within *moose-inventory*.
330
+ Note, the above conversions are performed automatically within *moose-inventory*.
336
331
 
337
- With *moose-inventory* installed and configured, and a shim script (e.g. *shim.sh*) in place, then use by Ansible can be acheived via Ansible's `-i` option.
332
+ With *moose-inventory* installed and configured, and a shim script (e.g. *shim.sh*) in place, then integration with Ansible can be acheived via Ansible's `-i <file>` option.
338
333
 
339
334
  ansible -i shim.sh -u ubuntu us-east-1d -m ping
340
335
 
341
- Alternatively, if you are using an [Ansible configuration file](http://docs.ansible.com/intro_configuration.html), then you can set the [inventory](http://docs.ansible.com/intro_configuration.html#inventory) option,
336
+ Alternatively, if using an [Ansible configuration file](http://docs.ansible.com/intro_configuration.html), then one may set the [inventory](http://docs.ansible.com/intro_configuration.html#inventory) option,
342
337
 
343
338
  inventory = ./shim.sh
344
339
 
345
340
  Yet another option is to copy the shim script to */etc/ansible/hosts* and `chmod +x` it. However, since this would essentially fix the config file and environment used, doing so would defeat the flexibility intended for *moose-inventory*.
346
341
 
342
+ To persist data from Ansible to the inventory, simply call the shim script via a local_action command, for example:
343
+
344
+ ```shell
345
+ - set_fact: mydata="Hello World"
346
+ - local_action: command shim.sh host addvar {{ ansible_host }} mydata={{ mydata }}
347
+ ```
348
+
349
+
350
+
347
351
  ## Contributing
348
352
  1. Fork it (https://github.com/RusDavies/moose-inventory/fork )
349
353
  2. Create your feature branch (git checkout -b my-new-feature`)
@@ -17,12 +17,12 @@ module Moose
17
17
 
18
18
  desc 'group ACTION',
19
19
  'Manipulate groups in the inventory. ' \
20
- 'ACTION can be add, rm, addhost, rmhost, addvar, rmvar'
20
+ 'ACTION can be add, rm, get, list, addhost, rmhost, addchild, rmchild, addvar, rmvar'
21
21
  subcommand 'group', Moose::Inventory::Cli::Group
22
22
 
23
23
  desc 'host ACTION',
24
24
  'Manipulate hosts in the inventory. ' \
25
- 'ACTION can be add, rm, addgroup, rmgroup, addvar, rmvar'
25
+ 'ACTION can be add, rm, get, list, addgroup, rmgroup, addvar, rmvar'
26
26
  subcommand 'host', Moose::Inventory::Cli::Host
27
27
  end
28
28
  end
@@ -2,6 +2,6 @@ module Moose
2
2
  ##
3
3
  # The Moose-Tools dynamic inventory management library
4
4
  module Inventory
5
- VERSION = '1.0.2'
5
+ VERSION = '1.0.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moose-inventory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Davies