ansibler 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/ansibler.gemspec +3 -2
- data/features/inventory/writing.feature +9 -0
- data/lib/ansible/inventory.rb +21 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad3f390ab2a019c1318d15733761a14e514f5fe9
|
4
|
+
data.tar.gz: 688864fd71078ef9019ae50404d65022597343be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6ab65dc5051e544afd29837c704a17e016c0d1f49caf0aafeaf087b9058feee1025f1b7ebc46a3cec04225fc739fdf00d1c114eace3ff7d5f74f8d2ff9c19a0
|
7
|
+
data.tar.gz: 88d93fadf6a0b8486900e200960469f0bf5432b9b0da32fc988f0351fa2925f7109ee2f24339945f8fb34981d9be25541d3e4c801912fcb717c0e37541c08c97
|
data/Rakefile
CHANGED
@@ -21,6 +21,7 @@ Jeweler::Tasks.new do |gem|
|
|
21
21
|
gem.description = 'ansibler is a Ruby gem that provides utility classes for modeling, reading and writing Ansible inventory and playbook files.'
|
22
22
|
gem.email = 'aisrael@gmail.com'
|
23
23
|
gem.authors = ['Alistair A. Israel']
|
24
|
+
gem.required_ruby_version = '>= 1.9'
|
24
25
|
|
25
26
|
# dependencies defined in Gemfile
|
26
27
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/ansibler.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: ansibler 0.2.
|
5
|
+
# stub: ansibler 0.2.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "ansibler"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
]
|
38
38
|
s.homepage = "http://github.com/aisrael/ansibler"
|
39
39
|
s.licenses = ["MIT"]
|
40
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
40
41
|
s.rubygems_version = "2.4.6"
|
41
42
|
s.summary = "Ruby gem for reading and writing Ansible files"
|
42
43
|
s.test_files = ["features/README.md", "features/inventory/reading.feature", "features/inventory/writing.feature", "features/step_definitions/common_steps.rb", "features/support/env.rb"]
|
@@ -27,3 +27,12 @@ Feature: Inventory Writing
|
|
27
27
|
[databases:children]
|
28
28
|
mysql
|
29
29
|
"""
|
30
|
+
|
31
|
+
Scenario: prevent adding the same host twice, even with vars
|
32
|
+
Given the following code snippet:
|
33
|
+
"""ruby
|
34
|
+
@ansible_inventory = Ansible::Inventory.new
|
35
|
+
@ansible_inventory.hosts.add 'host1', ansible_ssh_host: '172.31.3.134', ansible_ssh_user: 'ubuntu'
|
36
|
+
@ansible_inventory.hosts.add 'host1', ansible_ssh_user: 'ubuntu', ansible_ssh_host: '172.31.3.134'
|
37
|
+
"""
|
38
|
+
Then there should be 1 host
|
data/lib/ansible/inventory.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
1
3
|
module Ansible
|
2
4
|
|
3
5
|
class Inventory
|
@@ -28,10 +30,10 @@ module Ansible
|
|
28
30
|
child_group = inventory.groups[host_name] || inventory.groups.add(host_name)
|
29
31
|
last_group.children << child_group.name
|
30
32
|
elsif in_vars && host_name.index('=') && rest.empty?
|
31
|
-
k, v = host_name.split('=')
|
33
|
+
k, v = host_name.split('=', 2)
|
32
34
|
last_group.vars[k] = v
|
33
35
|
else
|
34
|
-
vars =
|
36
|
+
vars = ActiveSupport::HashWithIndifferentAccess[rest.map {|s| s.split('=', 2)}]
|
35
37
|
if last_group
|
36
38
|
host = inventory.hosts.find {|h| h.name == host_name} || Host.new(host_name, vars)
|
37
39
|
last_group.hosts << host
|
@@ -39,8 +41,6 @@ module Ansible
|
|
39
41
|
inventory.hosts.add host_name, vars
|
40
42
|
end
|
41
43
|
end
|
42
|
-
else
|
43
|
-
puts line
|
44
44
|
end
|
45
45
|
end
|
46
46
|
inventory
|
@@ -89,9 +89,12 @@ module Ansible
|
|
89
89
|
end
|
90
90
|
|
91
91
|
class Host < Struct.new :name, :vars
|
92
|
-
def initialize(
|
93
|
-
super
|
94
|
-
self.vars =
|
92
|
+
def initialize(name, hash = {})
|
93
|
+
super(name)
|
94
|
+
self.vars = ActiveSupport::HashWithIndifferentAccess.new(hash)
|
95
|
+
end
|
96
|
+
def ==(other)
|
97
|
+
(name == other.name) && (vars == other.vars)
|
95
98
|
end
|
96
99
|
class Collection < Array
|
97
100
|
def add(*args)
|
@@ -100,8 +103,16 @@ module Ansible
|
|
100
103
|
else
|
101
104
|
Host.new(*args)
|
102
105
|
end
|
103
|
-
|
104
|
-
host
|
106
|
+
# prevent dups
|
107
|
+
if existing = self.find {|h| h == host}
|
108
|
+
existing
|
109
|
+
else
|
110
|
+
self << host
|
111
|
+
host
|
112
|
+
end
|
113
|
+
end
|
114
|
+
def [](name)
|
115
|
+
find {|host| host.name == name}
|
105
116
|
end
|
106
117
|
end
|
107
118
|
end
|
@@ -110,7 +121,7 @@ module Ansible
|
|
110
121
|
def initialize(*args)
|
111
122
|
super
|
112
123
|
self.hosts = Host::Collection.new unless hosts
|
113
|
-
self.vars =
|
124
|
+
self.vars = ActiveSupport::HashWithIndifferentAccess.new(vars)
|
114
125
|
self.children = []
|
115
126
|
end
|
116
127
|
class Collection < Array
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansibler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alistair A. Israel
|
@@ -200,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
200
|
requirements:
|
201
201
|
- - ">="
|
202
202
|
- !ruby/object:Gem::Version
|
203
|
-
version: '
|
203
|
+
version: '1.9'
|
204
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - ">="
|