12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ansible_eyc_inventory.rb', line 12
def print_json(env_name, account_name)
env = api.env_by_name(env_name, account_name)
json = env.instances.group_by(&:role).each_with_object({}) {|(role, instances), memo|
memo[role] = instances.map(&:hostname)
}.merge(
_meta: {
hostvars: env.instances.each_with_object({}) {|instance, memo|
memo[instance.hostname] = {
ansible_ssh_user: env.username,
eyc_amazon_id: instance.amazon_id,
eyc_availability_zone: instance.availability_zone,
eyc_status: instance.status
}
}
}
)
puts JSON.pretty_generate(json)
rescue Error => e
warn e.message
exit 1
end
|