moose-inventory 1.0.7 → 1.0.8

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: aa64e991a9487d623df71257a5c1aaf59edda5b1
4
- data.tar.gz: 94b5ae699178d9fdba732e31878899bb988fa15b
3
+ metadata.gz: d4c867504f182214f4cb07980133ad5de8a68832
4
+ data.tar.gz: 99a656d44136b36bb7bd2c7187ec9ff66af51bb5
5
5
  SHA512:
6
- metadata.gz: 7d59d86537df3366dba60baff13c0656915bd42d6d17fd2bfe42080363c8aeef6dfba1e36deca4cdbf92fc59160b9f5d4a8afbb9d63f4ac17cd9ada2b2dc6bc3
7
- data.tar.gz: 22d2c8eb12465e4c51f7aad80669b2173f6e86501739be2310339b4c0633e9d3b4ad90145faa37525b96c02303ecfe3f011af54afc135562b63208818b9ba85d
6
+ metadata.gz: 3d1fe423b62518e54affd30939593ce8c8d6b0145424651a35aa30186bedd9ba195025abd7ef04385f082a7fedfb496a0aa75b994f1f52b724438e5b998745b7
7
+ data.tar.gz: d257057b70e3c25f043d0ae43faac496fe2e5461cf0bcad821196da30c5d86883d1620468bbdef1e6b91ecbb8476459af0eab62c0f0d8cc0d8552dab664aa29b
data/README.md CHANGED
@@ -2,14 +2,22 @@
2
2
 
3
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
- 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.
5
+ Note 1: For many, the really interesting part of this tool will be it's ability to write to the inventory database from within Ansible, as described at the end of this document. If that's what tickles your fancy, then I encourage you to get a sense of the capability by [jumping to that section first](https://github.com/RusDavies/moose-inventory#writing-to-the-dynamic-inventory-from-ansible). ;o)
6
+
7
+
8
+ Note 2: This software is intended for use on UNIX/Linux 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
9
 
7
10
  ## Installation
8
11
 
12
+ Note: You may need to install certain development tools (e.g. gcc, postresql-devel, mysql-devel, sqlite-devel) on your system, in order for the gem installation to perform native builds.
13
+
9
14
  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.
10
15
 
11
16
  $ gem install moose-inventory
12
17
 
18
+ Note: It may be necassary to first install certain development tools (e.g. gcc, postresql-devel, mysql-devel, sqlite-devel), in order for the gem installation to perform nati
19
+ ve builds.
20
+
13
21
  It can also be installed by adding the following line to a Gemfile and then executing `bundle`:
14
22
 
15
23
  ```ruby
@@ -306,6 +314,7 @@ Removing variables, groups, and hosts is just as easy. In the following example
306
314
 
307
315
  ### Using moose-inventory with Ansible
308
316
 
317
+
309
318
  The *moose-inventory* tool is compliant with the Ansible specifications for [dynamic inventory sources](http://docs.ansible.com/developing_inventory.html).
310
319
 
311
320
  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.
@@ -346,14 +355,14 @@ Alternatively, if using an [Ansible configuration file](http://docs.ansible.com/
346
355
 
347
356
  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*.
348
357
 
349
- To persist data from Ansible to the inventory, simply call the shim script via a local_action command, for example:
358
+ #### Writing to the dynamic inventory from Ansible
359
+ A useful aspect of dynamic inventories is the possibility of writing data to the inventory. To persist data from Ansible to the inventory, simply call the shim script via a local_action command, for example:
350
360
 
351
361
  ```shell
352
362
  - set_fact: mydata="Hello world"
353
363
  - local_action: command shim.sh host addvar {{ inventory_hostname }} mydata="{{ mydata }}"
354
364
  ```
355
365
 
356
-
357
366
 
358
367
  ## Contributing
359
368
  1. Fork it (https://github.com/RusDavies/moose-inventory/fork )
@@ -45,6 +45,23 @@ module Moose
45
45
  end
46
46
  fmt.puts 4, "- OK"
47
47
  unless group.nil?
48
+ # Dissociate from any parent groups
49
+ pgroups_ds = group.parents_dataset
50
+ pgroups_ds.each do |parent|
51
+ fmt.puts 2, "- Remove association {group:#{name} <-> group:#{parent.name}}..."
52
+ parent.remove_child(group)
53
+ fmt.puts 4, '- OK'
54
+ end
55
+
56
+ # Dissociate from any child groups
57
+ groups_ds = group.children_dataset
58
+ groups_ds.each do |child|
59
+ fmt.puts 2, "- Remove association {group:#{name} <-> group:#{child.name}}..."
60
+ group.remove_child(child)
61
+ # TODO: Should we propagate the delete to orphaned children?
62
+ fmt.puts 4, '- OK'
63
+ end
64
+
48
65
  # Handle automatic group for any associated hosts
49
66
  hosts_ds = group.hosts_dataset
50
67
  hosts_ds.each do |host|
@@ -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.7'
5
+ VERSION = '1.0.8'
6
6
  end
7
7
  end
@@ -184,8 +184,65 @@ RSpec.describe Moose::Inventory::Cli::Group do
184
184
 
185
185
 
186
186
  # Check db
187
- hosts = @db.models[:host].all
188
- expect(hosts.count).to eq(0)
187
+ groups = @db.models[:group].all
188
+ expect(groups.count).to eq(0)
189
189
  end
190
+
191
+ #---------------
192
+ it 'GROUP ... should remove GROUP, where GROUP has an associated parent.' do
193
+ @db.models[:group].create(name: "parent")
194
+ runner { @app.start(%w(group addchild parent child) ) }
195
+
196
+ actual = runner { @app.start(%w(group rm child) ) }
197
+
198
+ # Check output
199
+ desired = {STDOUT: ''}
200
+ # Check output
201
+ desired[:STDOUT] = desired[:STDOUT] +
202
+ "Remove group 'child':\n"\
203
+ " - Retrieve group 'child'...\n"\
204
+ " - OK\n"\
205
+ " - Remove association {group:child <-> group:parent}...\n"\
206
+ " - OK\n"\
207
+ " - Destroy group 'child'...\n"\
208
+ " - OK\n"\
209
+ " - All OK\n"
210
+
211
+ desired[:STDOUT] = desired[:STDOUT] + "Succeeded.\n"
212
+ expected(actual, desired)
213
+
214
+ # Check db
215
+ groups = @db.models[:group].all
216
+ expect(groups.count).to eq(1)
217
+ end
218
+
219
+ #---------------
220
+ it 'GROUP ... should remove GROUP, where GROUP has an associated child.' do
221
+ @db.models[:group].create(name: "parent")
222
+ runner { @app.start(%w(group addchild parent child) ) }
223
+
224
+ actual = runner { @app.start(%w(group rm parent) ) }
225
+
226
+ # Check output
227
+ desired = {STDOUT: ''}
228
+ # Check output
229
+ desired[:STDOUT] = desired[:STDOUT] +
230
+ "Remove group 'parent':\n"\
231
+ " - Retrieve group 'parent'...\n"\
232
+ " - OK\n"\
233
+ " - Remove association {group:parent <-> group:child}...\n"\
234
+ " - OK\n"\
235
+ " - Destroy group 'parent'...\n"\
236
+ " - OK\n"\
237
+ " - All OK\n"
238
+
239
+ desired[:STDOUT] = desired[:STDOUT] + "Succeeded.\n"
240
+ expected(actual, desired)
241
+
242
+ # Check db
243
+ groups = @db.models[:group].all
244
+ expect(groups.count).to eq(1)
245
+ end
246
+
190
247
  end
191
248
  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: 1.0.7
4
+ version: 1.0.8
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-08-03 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: indentation
@@ -355,7 +355,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
355
355
  version: '0'
356
356
  requirements: []
357
357
  rubyforge_project:
358
- rubygems_version: 2.2.3
358
+ rubygems_version: 2.2.5
359
359
  signing_key:
360
360
  specification_version: 4
361
361
  summary: Moose-tools inventory manager