moose-inventory 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +306 -19
- data/config/dotfiles/gitignore +1 -0
- data/lib/moose_inventory/config/config.rb +24 -7
- data/lib/moose_inventory/version.rb +1 -1
- data/scripts/work-through.sh +27 -0
- data/spec/lib/moose_inventory/cli/group_list_spec.rb +27 -4
- data/spec/lib/moose_inventory/cli/host_get_spec.rb +27 -0
- data/spec/lib/moose_inventory/cli/host_list_spec.rb +26 -4
- metadata +3 -3
- data/README.md.orig +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74c387f707f28fecdfe36ce2e7a11f8e94ba110
|
4
|
+
data.tar.gz: ba4e95aa06b584b7d85c6bde61b1c17bac7ff12b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a32a18f9c11cf4a9537f8368a457cb9167437b7abccd630d0ade37ec0a16978df3541c725c1ab1cc96958267e413e87b3a06131852795987c561daf406bd0c
|
7
|
+
data.tar.gz: f0e56af87553103d042b8bb057ca2ce06c78adacb06add897154ef9e9fb6f41a043e008e3396c13182e1a01e8f39ef926b8fbf29c9886c16000be72eaa860f8e
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# moose-inventory
|
2
2
|
|
3
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).
|
4
4
|
|
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
|
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
|
|
@@ -16,30 +16,32 @@ And then execute:
|
|
16
16
|
|
17
17
|
$ bundle
|
18
18
|
Or install it yourself as:
|
19
|
-
|
20
|
-
|
19
|
+
```ruby
|
20
|
+
$ gem install moose-inventory
|
21
|
+
```
|
21
22
|
|
22
23
|
## Configuration
|
23
24
|
The [moose-inventory](https://github.com/RusDavies/moose-inventory) tool makes use of a simple YAML configuration file.
|
24
25
|
|
25
26
|
|
26
|
-
###Location
|
27
|
+
###File Location
|
27
28
|
|
28
29
|
The following locations, in descending order of precedence, are searched for a configuration file:
|
29
|
-
|
30
|
+
|
31
|
+
1. location passed via the *-<sp>-config* CLI option
|
30
32
|
2. ./.moose-tools/inventory/config
|
31
33
|
4. ~/.moose-tools/inventory/config
|
32
34
|
5. ~/local/etc/moose-tools/inventory/config
|
33
35
|
6. /etc/moose-tools/inventory/config
|
34
36
|
|
35
37
|
###Format
|
36
|
-
The file
|
38
|
+
The file consists of a mandatory *general* section, and at least one environment section. For example:
|
37
39
|
```yaml
|
38
40
|
---
|
39
41
|
general:
|
40
42
|
defaultenv: moose_dev
|
41
43
|
|
42
|
-
moose_dev:
|
44
|
+
moose_dev:
|
43
45
|
db:
|
44
46
|
adapter: "sqlite3"
|
45
47
|
file: "~/.moose/db/dev.db"
|
@@ -62,29 +64,303 @@ another_example_section:
|
|
62
64
|
|
63
65
|
```
|
64
66
|
|
65
|
-
###The
|
66
|
-
The general section is mandatory, and contains a single parameter **defaultenv**, which points to the name of the default environment section.
|
67
|
+
###The *general* section
|
68
|
+
The general section is mandatory, and contains a single parameter **defaultenv**, which points to the name of the default environment section.
|
67
69
|
|
68
70
|
###Environment sections
|
69
71
|
You may add as many environment sections as you desire. The intention is to enable the user to easily manage multiple environments, such as development, staging, production, etc., via a single configuration file. The name of each environment section must be unique, but can otherwise be any valid YAML tag.
|
70
72
|
|
71
|
-
At present, each environment section contains only a **db** subsection, describing
|
73
|
+
At present, each environment section contains only a **db** subsection, describing database connection parameters. Additional subsections may be added in the future, as functionality increases.
|
72
74
|
|
73
|
-
Each **db** section must include an **adapter** parameter. Currently supported adapter types are sqlite3
|
75
|
+
Each **db** section must include an **adapter** parameter. Currently supported adapter types are *sqlite3*, *mysql*, and *postresql*. Note, as a matter of portability, only *sqlite3* is exercised via the test suite.
|
74
76
|
|
75
|
-
Additional parameters are also required in the **db** subsection, depending on the adapter type. For the sqlite3 adapter only a **file** parameter is required. For both mysql and postgresql
|
77
|
+
Additional parameters are also required in the **db** subsection, depending on the adapter type. For the *sqlite3* adapter only a **file** parameter is required. For both *mysql* and *postgresql*, then **host**, **database**, **user**, and **password** are the required parameters.
|
76
78
|
|
77
79
|
|
78
80
|
## Usage
|
81
|
+
### The help system
|
82
|
+
The tool itself provides a convenient help feature. For example,
|
83
|
+
|
84
|
+
> moose-inventory help
|
85
|
+
Commands:
|
86
|
+
moose-inventory group ACTION # Manipulate groups in…
|
87
|
+
moose-inventory help [COMMAND] # Describe available c…
|
88
|
+
⋮
|
89
|
+
|
90
|
+
and,
|
91
|
+
|
92
|
+
> moose-inventory help group
|
93
|
+
Commands:
|
94
|
+
moose-inventory group add NAME # Add a group NAME to …
|
95
|
+
moose-inventory group list # List the groups, tog…
|
96
|
+
⋮
|
97
|
+
|
98
|
+
and,
|
99
|
+
|
100
|
+
> moose-inventory group help add
|
101
|
+
Usage:
|
102
|
+
moose-inventory add NAME
|
103
|
+
|
104
|
+
Options:
|
105
|
+
[--hosts=HOSTS]
|
106
|
+
|
107
|
+
Add a group NAME to the inventory
|
108
|
+
|
109
|
+
###Global switches
|
110
|
+
Not described in the built-in help system are a handful of top-level switches, as follows.
|
111
|
+
|
112
|
+
#### - -config FILE
|
113
|
+
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 see in standard locations, see later.
|
114
|
+
|
115
|
+
For example,
|
116
|
+
|
117
|
+
> moose-inventory --config ./my_conf host list
|
118
|
+
|
119
|
+
#### - -env SECTION
|
120
|
+
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.
|
121
|
+
|
122
|
+
For example,
|
123
|
+
|
124
|
+
> moose-inventory --env my_section host list
|
125
|
+
|
126
|
+
#### - - format yaml|json|pjson
|
127
|
+
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.
|
128
|
+
|
129
|
+
For example,
|
130
|
+
|
131
|
+
> moose-inventory --format yaml host list
|
132
|
+
---
|
133
|
+
:test1:
|
134
|
+
:groups:
|
135
|
+
- ungrouped
|
136
|
+
|
137
|
+
###Transactional Behaviour
|
138
|
+
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.
|
139
|
+
|
140
|
+
###Walk-through examples
|
141
|
+
In this example, we will walk through the process of creating two hosts and two groups, assigning variables to each, and then then associating hosts with groups. Once done, we will then remove each association, variable, group and host.
|
142
|
+
|
143
|
+
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.
|
144
|
+
|
145
|
+
> moose-inventory add host host1 host2 host3
|
146
|
+
Add host 'host1':
|
147
|
+
- creating host 'host1'...
|
148
|
+
- OK
|
149
|
+
- add automatic association {host:host1 <-> group:ungrouped}...
|
150
|
+
- OK
|
151
|
+
- all OK
|
152
|
+
Add host 'host2':
|
153
|
+
- creating host 'host2'...
|
154
|
+
- OK
|
155
|
+
- add automatic association {host:host2 <-> group:ungrouped}...
|
156
|
+
- OK
|
157
|
+
- all OK
|
158
|
+
Add host 'host3':
|
159
|
+
- creating host 'host3'...
|
160
|
+
- OK
|
161
|
+
- add automatic association {host:host3 <-> group:ungrouped}...
|
162
|
+
- OK
|
163
|
+
- all OK
|
164
|
+
Succeeded.
|
165
|
+
|
166
|
+
Notice that each host is initially associated with an automatic group, *ungrouped*.
|
167
|
+
|
168
|
+
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.
|
169
|
+
|
170
|
+
> moose-inventory host list --format pjson
|
171
|
+
{
|
172
|
+
"host1": {
|
173
|
+
"groups": [
|
174
|
+
"ungrouped"
|
175
|
+
]
|
176
|
+
},
|
177
|
+
"host2": {
|
178
|
+
"groups": [
|
179
|
+
"ungrouped"
|
180
|
+
]
|
181
|
+
},
|
182
|
+
"host3": {
|
183
|
+
"groups": [
|
184
|
+
"ungrouped"
|
185
|
+
]
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
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.
|
190
|
+
|
191
|
+
> moose-inventory host get host3 host1 --format yaml
|
192
|
+
---
|
193
|
+
:host3:
|
194
|
+
:groups:
|
195
|
+
- ungrouped
|
196
|
+
:host1:
|
197
|
+
:groups:
|
198
|
+
- ungrouped
|
199
|
+
|
200
|
+
Now we'll add some host variables. Again, we can add as many variables to a host as we desire.
|
201
|
+
|
202
|
+
> moose-inventory host addvar host1 owner=russell id=12345
|
203
|
+
Add variables 'owner=russell,id=12345' to host 'host1':
|
204
|
+
- retrieve host 'host1'...
|
205
|
+
- OK
|
206
|
+
- add variable 'owner=russell'...
|
207
|
+
- OK
|
208
|
+
- add variable 'id=12345'...
|
209
|
+
- OK
|
210
|
+
- all OK
|
211
|
+
Succeeded.
|
212
|
+
|
213
|
+
> moose-inventory host addvar host2 owner=caroline id=54321
|
214
|
+
Add variables 'owner=caroline,id=54321' to host 'host2':
|
215
|
+
- retrieve host 'host2'...
|
216
|
+
- OK
|
217
|
+
- add variable 'owner=caroline'...
|
218
|
+
- OK
|
219
|
+
- add variable 'id=54321'...
|
220
|
+
- OK
|
221
|
+
- all OK
|
222
|
+
Succeeded.
|
223
|
+
|
224
|
+
Let's list our hosts again, to see what that looks like.
|
225
|
+
|
226
|
+
> moose-inventory host list --format yaml
|
227
|
+
---
|
228
|
+
:host1:
|
229
|
+
:groups:
|
230
|
+
- ungrouped
|
231
|
+
:hostvars:
|
232
|
+
:owner: russell
|
233
|
+
:id: '12345'
|
234
|
+
:host2:
|
235
|
+
:groups:
|
236
|
+
- ungrouped
|
237
|
+
:hostvars:
|
238
|
+
:owner: caroline
|
239
|
+
:id: '54321'
|
240
|
+
:host3:
|
241
|
+
:groups:
|
242
|
+
- ungrouped
|
243
|
+
|
244
|
+
As you can see, the hosts with variables each have a new section, hostvars, in which those variables are listed. Try also with *--format pjson*.
|
245
|
+
|
246
|
+
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.
|
247
|
+
|
248
|
+
> moose-inventory group add group1 group2 group3
|
249
|
+
> moose-inventory group list --format yaml
|
250
|
+
> moose-inventory group get ungrouped group2 --format yaml
|
251
|
+
> moose-inventory group addvar group1 location=usa
|
252
|
+
> moose-inventory group addvar group2 location=europe
|
253
|
+
|
254
|
+
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,
|
255
|
+
|
256
|
+
> moose-inventory group addhost group1 host1 host2
|
257
|
+
Associate group 'group1' with host(s) 'host1,host2':
|
258
|
+
- retrieve group 'group1'...
|
259
|
+
- OK
|
260
|
+
- add association {group:group1 <-> host:host1}...
|
261
|
+
- OK
|
262
|
+
- remove automatic association {group:ungrouped <-> host:host1}...
|
263
|
+
- OK
|
264
|
+
- add association {group:group1 <-> host:host2}...
|
265
|
+
- OK
|
266
|
+
- remove automatic association {group:ungrouped <-> host:host2}...
|
267
|
+
- OK
|
268
|
+
- all OK
|
269
|
+
Succeeded.
|
270
|
+
|
271
|
+
or one or more groups with a host,
|
272
|
+
|
273
|
+
> moose-inventory host addgroup host3 group2 group3
|
274
|
+
Associate host 'host3' with groups 'group2,group3':
|
275
|
+
- Retrieve host 'host3'...
|
276
|
+
- OK
|
277
|
+
- Add association {host:host3 <-> group:group2}...
|
278
|
+
- OK
|
279
|
+
- Add association {host:host3 <-> group:group3}...
|
280
|
+
- OK
|
281
|
+
- Remove automatic association {host:host3 <-> group:ungrouped}...
|
282
|
+
- OK
|
283
|
+
- All OK
|
284
|
+
Succeeded
|
285
|
+
|
286
|
+
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.
|
287
|
+
|
288
|
+
> moose-inventory group list --format yaml
|
289
|
+
---
|
290
|
+
:ungrouped: {}
|
291
|
+
:group1:
|
292
|
+
:hosts:
|
293
|
+
- host1
|
294
|
+
- host2
|
295
|
+
:groupvars:
|
296
|
+
:location: usa
|
297
|
+
:group2:
|
298
|
+
:hosts:
|
299
|
+
- host3
|
300
|
+
:group3:
|
301
|
+
:hosts:
|
302
|
+
- host3
|
303
|
+
|
304
|
+
We can also list hosts, to get the host-centric view.
|
305
|
+
|
306
|
+
---
|
307
|
+
:host1:
|
308
|
+
:groups:
|
309
|
+
- group1
|
310
|
+
:hostvars:
|
311
|
+
:owner: russell
|
312
|
+
:id: '12345'
|
313
|
+
:host2:
|
314
|
+
:groups:
|
315
|
+
- group1
|
316
|
+
:hostvars:
|
317
|
+
:owner: caroline
|
318
|
+
:id: '54321'
|
319
|
+
:host3:
|
320
|
+
:groups:
|
321
|
+
- group2
|
322
|
+
- group3
|
323
|
+
|
324
|
+
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.
|
325
|
+
|
326
|
+
> moose-inventory group rmvar group1 location
|
327
|
+
> moose-inventory group rm group1 group2 group3
|
328
|
+
> moose-inventory host rmvar
|
329
|
+
> moose-inventory host rmvar host1 owner id
|
330
|
+
> moose-inventory host rm host1 host2 host3
|
331
|
+
|
332
|
+
### Using moose-inventory with Ansible
|
333
|
+
For integration with Ansible, a shim script should be used, in order to set the correct configuration file, environment, etc.
|
334
|
+
|
335
|
+
A trivial shim script, to be provided to Ansible as the [external inventory script](http://docs.ansible.com/intro_dynamic_inventory.html), may look like this,
|
336
|
+
```bash
|
337
|
+
#!/bin/bash
|
338
|
+
|
339
|
+
CONF='./example.conf'
|
340
|
+
ENV='dev'
|
341
|
+
|
342
|
+
moose-inventory --config $CONF --env $ENV $@
|
343
|
+
|
344
|
+
exit $?
|
345
|
+
```
|
346
|
+
When Ansible calls the external inventory script, it does so using the certain parameters, which *moose-inventory* recognises. The Ansible parameters, and their equivalent *moose-inventory* native parameters are shown below.
|
347
|
+
|
348
|
+
Ansible params | moose-inventory params
|
349
|
+
---------------- |-------------
|
350
|
+
-<sp>-hosts | host list
|
351
|
+
-<sp>-hosts HOST | host get HOST
|
352
|
+
--groups | group list
|
353
|
+
|
354
|
+
Note, the above conversions are done automatically by the tool, and are included here only for reference.
|
355
|
+
|
356
|
+
With *moose-inventory* installed and configured, and a shim script (e.g. shim.sh) in place, then using Ansible would be a bit like this:
|
357
|
+
|
358
|
+
ansible -i shim.sh -u ubuntu us-east-1d -m ping
|
79
359
|
|
80
360
|
##Missing features
|
81
361
|
The following desired features are yet to be implemented:
|
82
|
-
|
83
|
-
|
84
|
-
-- CLI:Group shall provided an addchild method.
|
85
|
-
-- CLI:Group shall provided a rmchild method.
|
86
|
-
-- CLI:Group.get method shall display child group relationships.
|
87
|
-
-- CLI:Group.list method shall display child group relationships.
|
362
|
+
|
363
|
+
1. Groups of groups
|
88
364
|
|
89
365
|
## Contributing
|
90
366
|
1. Fork it (https://github.com/RusDavies/moose-inventory/fork )
|
@@ -92,3 +368,14 @@ The following desired features are yet to be implemented:
|
|
92
368
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
93
369
|
4. Push to the branch (`git push origin my-new-feature`)
|
94
370
|
5. Create a new Pull Request
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
data/config/dotfiles/gitignore
CHANGED
@@ -23,8 +23,9 @@ module Moose
|
|
23
23
|
def self.init(args)
|
24
24
|
@_argv = args.dup
|
25
25
|
|
26
|
+
top_level_help
|
26
27
|
top_level_args
|
27
|
-
|
28
|
+
ansible_args
|
28
29
|
resolve_config_file
|
29
30
|
load
|
30
31
|
end
|
@@ -65,28 +66,44 @@ module Moose
|
|
65
66
|
|
66
67
|
end
|
67
68
|
|
69
|
+
#----------------------
|
70
|
+
def self.top_level_help
|
71
|
+
if @_argv[0] == 'help'
|
72
|
+
puts "Global flags:"
|
73
|
+
printf " %-31s %-10s", "--config FILE", "# Specified configuration file to use\n"
|
74
|
+
printf " %-31s %-10s", "--config FILE", "# Specifies a configuration file to use\n"
|
75
|
+
printf " %-31s %-10s", "--env ENV", "# Specifies the environment section of the config to use\n"
|
76
|
+
printf " %-31s %-10s", "--format yaml|json|pjson", "# Format for the output of 'get' and 'list'\n"
|
77
|
+
puts "\nAnsible flags:"
|
78
|
+
printf " %-31s %-10s", "--hosts", "# Retrieves the list of hosts (alias for 'host list'\n"
|
79
|
+
printf " %-31s %-10s", "--hosts HOST", "# Retrieves the specified host (alias for 'host get HOST')\n"
|
80
|
+
printf " %-31s %-10s", "--groups", "# Retrieves the list of groups (alias for 'group list')\n\n"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
68
84
|
#----------------------
|
69
85
|
def self.ansible_args # rubocop:disable Metrics/AbcSize
|
70
86
|
# Handle Ansible flags
|
71
|
-
# --hosts => list
|
72
|
-
# --hosts HOSTNAME => get
|
73
|
-
# --groups => list
|
87
|
+
# --hosts => host list
|
88
|
+
# --hosts HOSTNAME => host get HOSTNAME
|
89
|
+
# --groups => lgroup list
|
74
90
|
|
75
91
|
if @_argv[0] == '--hosts'
|
76
92
|
host = @_argv[1]
|
77
93
|
if !host.nil?
|
78
94
|
@_argv.clear
|
79
|
-
['host', 'get', "#{host}"
|
95
|
+
['host', 'get', "#{host}"].each do |arg|
|
80
96
|
@_argv << arg
|
81
97
|
end
|
82
98
|
else
|
83
99
|
@_argv.clear
|
84
|
-
['host', 'list'
|
100
|
+
['host', 'list'].each do |arg|
|
85
101
|
@_argv << arg
|
86
102
|
end
|
87
103
|
end
|
88
104
|
elsif @_argv[0] == '--groups'
|
89
|
-
|
105
|
+
@_argv.clear
|
106
|
+
['group', 'list'].each do |arg|
|
90
107
|
@_argv << arg
|
91
108
|
end
|
92
109
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
moose-inventory help
|
3
|
+
moose-inventory help group
|
4
|
+
moose-inventory group help add
|
5
|
+
moose-inventory host add host1 host2 host3
|
6
|
+
moose-inventory host list --format pjson
|
7
|
+
moose-inventory host get host3 host1 --format yaml
|
8
|
+
moose-inventory host addvar owner=russell
|
9
|
+
moose-inventory host addvar host1 owner=russell id=12345
|
10
|
+
moose-inventory host addvar host2 owner=caroline id=54321
|
11
|
+
moose-inventory host list --format yaml
|
12
|
+
moose-inventory group add group1 group2 group3
|
13
|
+
moose-inventory group list --format yaml
|
14
|
+
moose-inventory group get ungrouped group3 --format yaml
|
15
|
+
moose-inventory group addvar location=usa
|
16
|
+
moose-inventory group addvar group1 location=usa
|
17
|
+
moose-inventory group addhost group1 host1 host2
|
18
|
+
moose-inventory host addgroup host3 group2 group3
|
19
|
+
moose-inventory group list --format yaml
|
20
|
+
moose-inventory host list --format yaml
|
21
|
+
moose-inventory group rmvar group1 location
|
22
|
+
moose-inventory group list --format y
|
23
|
+
moose-inventory group rm group1 group2 group3
|
24
|
+
moose-inventory host rmvar host1 owner id
|
25
|
+
moose-inventory host rm host1 host2 host3
|
26
|
+
moose-inventory host list
|
27
|
+
moose-inventory group list
|
@@ -21,6 +21,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
21
21
|
@db = Moose::Inventory::DB
|
22
22
|
@db.init if @db.db.nil?
|
23
23
|
|
24
|
+
@console = Moose::Inventory::Cli::Formatter
|
24
25
|
@group = Moose::Inventory::Cli::Group
|
25
26
|
@app = Moose::Inventory::Cli::Application
|
26
27
|
end
|
@@ -70,10 +71,32 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
70
71
|
|
71
72
|
expected(actual, desired)
|
72
73
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
|
75
|
+
#---------------------
|
76
|
+
it 'should be an alias of --groups (i.e. Ansible parameter)' do
|
77
|
+
|
78
|
+
host_name = 'test_host'
|
79
|
+
|
80
|
+
mock = {}
|
81
|
+
groups = %w(group1 group2 group3)
|
82
|
+
groups.each do |name|
|
83
|
+
runner { @app.start(%W(group add #{name})) }
|
84
|
+
mock[name.to_sym] = {}
|
85
|
+
end
|
86
|
+
|
87
|
+
args = @mockargs.clone
|
88
|
+
args << "--groups"
|
89
|
+
cli = Moose::Inventory::Cli
|
90
|
+
|
91
|
+
actual = runner{ cli.start(args) }
|
92
|
+
|
93
|
+
#@console.out(actual, 'y')
|
94
|
+
|
95
|
+
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
96
|
+
desired[:STDOUT] = mock.to_yaml
|
97
|
+
|
98
|
+
expected(actual, desired)
|
99
|
+
end
|
77
100
|
|
78
101
|
end
|
79
102
|
end
|
@@ -101,6 +101,33 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
101
101
|
|
102
102
|
expected(actual, desired)
|
103
103
|
end
|
104
|
+
|
105
|
+
#---------------------
|
106
|
+
it 'should be an alias of --hosts HOST (i.e. Ansible parameter)' do
|
107
|
+
|
108
|
+
mock = {}
|
109
|
+
host = 'host1'
|
110
|
+
|
111
|
+
runner { @app.start(%W(host add #{host})) }
|
112
|
+
mock[host.to_sym] = {}
|
113
|
+
mock[host.to_sym][:groups] = ['ungrouped']
|
114
|
+
|
115
|
+
args = @mockargs.clone
|
116
|
+
args << '--hosts'
|
117
|
+
args << "#{host}"
|
118
|
+
cli = Moose::Inventory::Cli
|
119
|
+
|
120
|
+
# items should now be in the db
|
121
|
+
actual = runner{ cli.start(args) }
|
122
|
+
|
123
|
+
#@console.out(actual, 'y')
|
124
|
+
|
125
|
+
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
126
|
+
desired[:STDOUT] = mock.to_yaml
|
127
|
+
|
128
|
+
expected(actual, desired)
|
129
|
+
end
|
130
|
+
|
104
131
|
|
105
132
|
end
|
106
133
|
end
|
@@ -16,7 +16,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
16
16
|
@mockarg_parts.each do |key, val|
|
17
17
|
@mockargs << "--#{key}"
|
18
18
|
@mockargs << val
|
19
|
-
end
|
19
|
+
end
|
20
20
|
|
21
21
|
@config = Moose::Inventory::Config
|
22
22
|
@config.init(@mockargs)
|
@@ -24,6 +24,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
24
24
|
@db = Moose::Inventory::DB
|
25
25
|
@db.init if @db.db.nil?
|
26
26
|
|
27
|
+
@console = Moose::Inventory::Cli::Formatter
|
27
28
|
@host = Moose::Inventory::Cli::Host
|
28
29
|
@app = Moose::Inventory::Cli::Application
|
29
30
|
end
|
@@ -75,9 +76,30 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
75
76
|
expected(actual, desired)
|
76
77
|
end
|
77
78
|
#---------------------
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
it 'should be an alias of --hosts (i.e. Ansible parameter)' do
|
80
|
+
|
81
|
+
mock = {}
|
82
|
+
hosts = %w(host1 host2)
|
83
|
+
hosts.each do |name|
|
84
|
+
runner { @app.start(%W(host add #{name})) }
|
85
|
+
mock[name.to_sym] = {}
|
86
|
+
mock[name.to_sym][:groups] = ['ungrouped']
|
87
|
+
end
|
88
|
+
|
89
|
+
args = @mockargs.clone
|
90
|
+
args << "--hosts"
|
91
|
+
cli = Moose::Inventory::Cli
|
92
|
+
|
93
|
+
# items should now be in the db
|
94
|
+
actual = runner{ cli.start(args) }
|
95
|
+
|
96
|
+
#@console.out(actual, 'y')
|
97
|
+
|
98
|
+
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
99
|
+
desired[:STDOUT] = mock.to_yaml
|
100
|
+
|
101
|
+
expected(actual, desired)
|
102
|
+
end
|
81
103
|
|
82
104
|
end
|
83
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moose-inventory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Davies
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: indentation
|
@@ -263,7 +263,6 @@ files:
|
|
263
263
|
- Guardfile
|
264
264
|
- LICENSE.txt
|
265
265
|
- README.md
|
266
|
-
- README.md.orig
|
267
266
|
- Rakefile
|
268
267
|
- bin/moose-inventory
|
269
268
|
- config/dotfiles/coveralls.yml
|
@@ -302,6 +301,7 @@ files:
|
|
302
301
|
- scripts/guard_quality.sh
|
303
302
|
- scripts/guard_test.sh
|
304
303
|
- scripts/reports.sh
|
304
|
+
- scripts/work-through.sh
|
305
305
|
- spec/config/config.yml
|
306
306
|
- spec/lib/moose_inventory/cli/application_spec.rb
|
307
307
|
- spec/lib/moose_inventory/cli/cli_spec.rb
|
data/README.md.orig
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
<<<<<<< HEAD
|
2
|
-
# Moose::Inventory
|
3
|
-
|
4
|
-
TODO: Write a gem description
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'moose-inventory'
|
12
|
-
```
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
|
16
|
-
$ bundle
|
17
|
-
|
18
|
-
Or install it yourself as:
|
19
|
-
|
20
|
-
$ gem install moose-inventory
|
21
|
-
|
22
|
-
## Usage
|
23
|
-
|
24
|
-
TODO: Write usage instructions here
|
25
|
-
|
26
|
-
## Contributing
|
27
|
-
|
28
|
-
1. Fork it ( https://github.com/[my-github-username]/moose-inventory/fork )
|
29
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
-
5. Create a new Pull Request
|
33
|
-
=======
|
34
|
-
# TODO
|
35
|
-
>>>>>>> ce0f5f71b122cc7b740560e875f2fc0a452da107
|