moose-inventory 1.0.3 → 1.0.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 570b23a90a452e12fb6aa8f03e5b9613a3c365ff
|
4
|
+
data.tar.gz: 152441118aedc1f0935510e6f9c7357d514553b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15a262e2ac4d8bab1fc356b7f60aceb612544d09a1df770952199eabe4668923dae44d40cf2d76460939f197374208bef687c8e33a70f575979a9635bbceaa38
|
7
|
+
data.tar.gz: 44eb25e1744164bc618c5d54ae52bc926f30f8e5c265939fb7ae53dd857ec8c676831089713b1d674f7c17079d723bbf310189d890a88bf76e163ca4649ff094
|
data/README.md
CHANGED
@@ -308,7 +308,7 @@ Removing variables, groups, and hosts is just as easy. In the following example
|
|
308
308
|
|
309
309
|
The *moose-inventory* tool is compliant with the Ansible specifications for [dynamic inventory sources](http://docs.ansible.com/developing_inventory.html).
|
310
310
|
|
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
|
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 the following.
|
312
312
|
|
313
313
|
```shell
|
314
314
|
#!/bin/bash
|
@@ -316,10 +316,17 @@ However, to make use of *moose-inventory's* multiple environment and configurati
|
|
316
316
|
CONF='./example.conf'
|
317
317
|
ENV='dev'
|
318
318
|
|
319
|
-
moose-inventory --config $CONF --env $ENV $@
|
319
|
+
moose-inventory --config $CONF --env $ENV "$@"
|
320
320
|
|
321
321
|
exit $?
|
322
322
|
```
|
323
|
+
|
324
|
+
**IMPORTANT**: Take care to notice that "$@" is the quoted form. In fact, $@ and "$@" behave differently in how they handle white space. If you expect spaces in your variable names or values, such as in the following example, then you must use the quoted form "$@".
|
325
|
+
|
326
|
+
$ ./shim.sh host add example
|
327
|
+
$ ./shim.sh host addvar example "my var"="hello world"
|
328
|
+
|
329
|
+
|
323
330
|
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.
|
324
331
|
|
325
332
|
Ansible | moose-inventory
|
@@ -342,8 +349,8 @@ Yet another option is to copy the shim script to */etc/ansible/hosts* and `chmod
|
|
342
349
|
To persist data from Ansible to the inventory, simply call the shim script via a local_action command, for example:
|
343
350
|
|
344
351
|
```shell
|
345
|
-
- set_fact: mydata="Hello
|
346
|
-
- local_action: command shim.sh host addvar {{
|
352
|
+
- set_fact: mydata="Hello world"
|
353
|
+
- local_action: command shim.sh host addvar {{ inventory_hostname }} mydata="{{ mydata }}"
|
347
354
|
```
|
348
355
|
|
349
356
|
|
@@ -113,7 +113,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
#------------------------
|
116
|
-
|
116
|
+
fit 'host addvar HOST key=value ... should associate the host with the key/value pair' do
|
117
117
|
# 1. Should add the var to the db
|
118
118
|
# 2. Should associate the host with the var
|
119
119
|
|
@@ -145,7 +145,41 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
145
145
|
expect(hostvars[name: var[:name]]).not_to be_nil
|
146
146
|
expect(hostvars[name: var[:name]][:value]).to eq(var[:value])
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
|
+
#------------------------
|
150
|
+
fit 'host addvar HOST "my val"="hello world" ... should associate the host with the key/value pair' do
|
151
|
+
# 1. Should add the var to the db
|
152
|
+
# 2. Should associate the host with the var
|
153
|
+
|
154
|
+
host_name = 'test1'
|
155
|
+
var = {name: 'my val', value: "hello world"}
|
156
|
+
|
157
|
+
@db.models[:host].create(name: host_name)
|
158
|
+
|
159
|
+
actual = runner do
|
160
|
+
@app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]} ))
|
161
|
+
end
|
162
|
+
#@console.out(actual,'p')
|
163
|
+
|
164
|
+
desired = { aborted: false}
|
165
|
+
desired[:STDOUT] =
|
166
|
+
"Add variables '#{var[:name]}=#{var[:value]}' to host '#{host_name}':\n"\
|
167
|
+
" - retrieve host '#{host_name}'...\n"\
|
168
|
+
" - OK\n"\
|
169
|
+
" - add variable '#{var[:name]}=#{var[:value]}'...\n"\
|
170
|
+
" - OK\n"\
|
171
|
+
" - all OK\n"\
|
172
|
+
"Succeeded.\n"
|
173
|
+
expected(actual, desired)
|
174
|
+
|
175
|
+
# We should have the correct hostvar associations
|
176
|
+
host = @db.models[:host].find(name: host_name)
|
177
|
+
hostvars = host.hostvars_dataset
|
178
|
+
expect(hostvars.count).to eq(1)
|
179
|
+
expect(hostvars[name: var[:name]]).not_to be_nil
|
180
|
+
expect(hostvars[name: var[:name]][:value]).to eq(var[:value])
|
181
|
+
end
|
182
|
+
|
149
183
|
#------------------------
|
150
184
|
it 'host addvar HOST key1=value1 key2=value2 ... should associate the host with multiple key/value pairs' do
|
151
185
|
# 1. Should add the var to the db
|
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: 1.0.
|
4
|
+
version: 1.0.4
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: indentation
|