hostlist 1.0.0 → 1.0.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/CHANGELOG.md +7 -0
- data/hostlist.gemspec +2 -2
- data/hostlist.yaml.sample +6 -24
- data/lib/hostlist.rb +34 -8
- data/lib/hostlist/thor.rb +8 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4266c1df363e182991664e06d5e2539f24058381
|
4
|
+
data.tar.gz: 04faaf5028f85b7788c14451a500ced947681b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ea67e99d1d1817768f7faf43ba1dec867e44c0f52e8e2e1f1c1e5e94b6e2f63cd718c18531403055c85f9f8fbdceec4192380319473328c253496e75ff4700
|
7
|
+
data.tar.gz: caa145c6285ecb4721c0bbad9f291009c3667c1e6f2ee9941ff1b09a4946286607bc8c450adafccd1be4f71292ad9197e96476bd6b68f05a500e2d1db9e918fb
|
data/CHANGELOG.md
ADDED
data/hostlist.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'hostlist'
|
3
|
-
gem.version = '1.0.
|
3
|
+
gem.version = '1.0.2'
|
4
4
|
gem.licenses = ['MIT']
|
5
|
-
gem.date = '2015-
|
5
|
+
gem.date = '2015-08-31'
|
6
6
|
gem.summary = 'Host List Generator'
|
7
7
|
gem.description = 'Generates list of hosts based on tags.'
|
8
8
|
gem.authors = ['Zan Loy']
|
data/hostlist.yaml.sample
CHANGED
@@ -1,24 +1,6 @@
|
|
1
|
-
'
|
2
|
-
tags: [ 'prd', 'pxy', '
|
3
|
-
'
|
4
|
-
tags: [ 'prd', '
|
5
|
-
'
|
6
|
-
tags: [ 'prd', '
|
7
|
-
'extpxy004.prd.vbms.vba.va.gov':
|
8
|
-
tags: [ 'prd', 'pxy', 'extpxy']
|
9
|
-
'vbms000.prd.vbms.vba.va.gov':
|
10
|
-
tags: [ 'prd', 'weblogic', 'vbms' ]
|
11
|
-
'vbms001.prd.vbms.vba.va.gov':
|
12
|
-
tags: [ 'prd', 'weblogic', 'vbms' ]
|
13
|
-
'extpxy001.pre.vbms.vba.va.gov':
|
14
|
-
tags: [ 'pre', 'pxy', 'extpxy']
|
15
|
-
'extpxy002.pre.vbms.vba.va.gov':
|
16
|
-
tags: [ 'pre', 'pxy', 'extpxy']
|
17
|
-
'extpxy001.prdtst.vbms.vba.va.gov':
|
18
|
-
tags: [ 'prdtst', 'pxy', 'extpxy']
|
19
|
-
'extpxy002.prdtst.vbms.vba.va.gov':
|
20
|
-
tags: [ 'prdtst', 'pxy', 'extpxy']
|
21
|
-
'extpxy001.perf.vbms.vba.va.gov':
|
22
|
-
tags: [ 'perf', 'pxy', 'extpxy']
|
23
|
-
'extpxy002.perf.vbms.vba.va.gov':
|
24
|
-
tags: [ 'perf', 'pxy', 'extpxy']
|
1
|
+
'www00{1,2}.example.com':
|
2
|
+
tags: [ 'prd', 'pxy', 'www']
|
3
|
+
'app00{1..4}.example.com':
|
4
|
+
tags: [ 'prd', 'app']
|
5
|
+
'db001.example.com':
|
6
|
+
tags: [ 'prd', 'db']
|
data/lib/hostlist.rb
CHANGED
@@ -10,18 +10,12 @@ class HostList
|
|
10
10
|
@db_filename = cache
|
11
11
|
end
|
12
12
|
|
13
|
+
# Return array based on tags. Tags can be a string or array of strings.
|
13
14
|
def list(tags)
|
14
15
|
tags = [tags] if tags.is_a? String
|
15
16
|
# Verify we have the most recent data in our daybreak cache.
|
16
17
|
db = open_db
|
17
18
|
begin
|
18
|
-
if db.has_key? :md5
|
19
|
-
file_md5 = Digest::MD5.file @yaml
|
20
|
-
generate_db(db) unless file_md5 == db[:md5]
|
21
|
-
else
|
22
|
-
generate_db(db)
|
23
|
-
end
|
24
|
-
db.load
|
25
19
|
# Collect all the tags from the database
|
26
20
|
hosts = []
|
27
21
|
if tags.empty?
|
@@ -66,10 +60,19 @@ class HostList
|
|
66
60
|
end
|
67
61
|
end
|
68
62
|
|
63
|
+
# Open cache database
|
69
64
|
def open_db
|
70
|
-
Daybreak::DB.new File.expand_path(@db_filename)
|
65
|
+
db = Daybreak::DB.new File.expand_path(@db_filename)
|
66
|
+
if db.has_key? :md5
|
67
|
+
file_md5 = Digest::MD5.file @yaml
|
68
|
+
generate_db(db) unless file_md5 == db[:md5]
|
69
|
+
else
|
70
|
+
generate_db(db)
|
71
|
+
end
|
72
|
+
return db
|
71
73
|
end
|
72
74
|
|
75
|
+
# Read in yaml file and cache to database
|
73
76
|
def generate_db(db)
|
74
77
|
db.clear
|
75
78
|
db[:all] = []
|
@@ -90,4 +93,27 @@ class HostList
|
|
90
93
|
db.flush
|
91
94
|
end
|
92
95
|
|
96
|
+
# Export the host list as an ansible hosts file.
|
97
|
+
def export_ansible(filename = '/etc/ansible/hosts')
|
98
|
+
db = open_db
|
99
|
+
output = []
|
100
|
+
begin
|
101
|
+
db.keys.each do |key|
|
102
|
+
next if key == 'md5'
|
103
|
+
output << "[#{key}]"
|
104
|
+
db[key].each do |host|
|
105
|
+
output << host
|
106
|
+
end
|
107
|
+
end
|
108
|
+
output = output.join("\n")
|
109
|
+
if filename and File.writable? filename
|
110
|
+
File.open(filename, 'w') { |f| f.write(output) }
|
111
|
+
else
|
112
|
+
puts output
|
113
|
+
end
|
114
|
+
ensure
|
115
|
+
db.close
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
93
119
|
end
|
data/lib/hostlist/thor.rb
CHANGED
@@ -19,16 +19,22 @@ class HostListThor < Thor
|
|
19
19
|
hostlist.list(tags).each { |host| puts host }
|
20
20
|
end
|
21
21
|
|
22
|
-
desc '
|
22
|
+
desc 'show', 'Show all the tags in the cache database.'
|
23
23
|
def show
|
24
24
|
hostlist = HostList.new(yaml: options[:yaml], cache: options[:db])
|
25
25
|
hostlist.keys.each { |key| puts key }
|
26
26
|
end
|
27
27
|
|
28
|
-
desc 'print_db', 'Print the contents of the database for debugging purposes'
|
28
|
+
desc 'print_db', 'Print the contents of the database for debugging purposes.'
|
29
29
|
def print_db
|
30
30
|
hostlist = HostList.new(yaml: options[:yaml], cache: options[:db])
|
31
31
|
hostlist.print_db
|
32
32
|
end
|
33
33
|
|
34
|
+
desc 'print_ansible', 'Print out the ansible hosts to stdout.'
|
35
|
+
def print_ansible
|
36
|
+
hostlist = HostList.new(yaml: options[:yaml], cache: options[:db])
|
37
|
+
hostlist.export_ansible(nil)
|
38
|
+
end
|
39
|
+
|
34
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hostlist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zan Loy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bracecomp
|
@@ -78,6 +78,7 @@ executables:
|
|
78
78
|
extensions: []
|
79
79
|
extra_rdoc_files: []
|
80
80
|
files:
|
81
|
+
- CHANGELOG.md
|
81
82
|
- README.md
|
82
83
|
- Rakefile
|
83
84
|
- bin/hostlist
|
@@ -110,3 +111,4 @@ signing_key:
|
|
110
111
|
specification_version: 4
|
111
112
|
summary: Host List Generator
|
112
113
|
test_files: []
|
114
|
+
has_rdoc:
|