Skip to content
Snippets Groups Projects
Commit c0136f80 authored by jurgenhaas's avatar jurgenhaas
Browse files

New option to output the downloaded settings from ServerDensity as a yaml file

parent a263b318
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import json ...@@ -2,6 +2,7 @@ import json
import os import os
import requests import requests
import tempfile import tempfile
import yaml
from ansible.callbacks import vv from ansible.callbacks import vv
from ansible.errors import AnsibleError as ae from ansible.errors import AnsibleError as ae
...@@ -58,6 +59,13 @@ class ActionModule(object): ...@@ -58,6 +59,13 @@ class ActionModule(object):
if just_download: if just_download:
vv('Downloaded settings to %s' % self.cache_file_name) vv('Downloaded settings to %s' % self.cache_file_name)
output = args.get('output', False)
if output:
if os.path.exists(self.cache_file_name):
with open(self.cache_file_name, 'r') as content_file:
content = json.load(content_file)
with open(output, 'w') as output_file:
yaml.safe_dump(content, output_file, encoding='utf-8', allow_unicode=True)
return ReturnData(conn=conn, comm_ok=True, result=result) return ReturnData(conn=conn, comm_ok=True, result=result)
services = {} services = {}
...@@ -111,7 +119,7 @@ class ActionModule(object): ...@@ -111,7 +119,7 @@ class ActionModule(object):
os={ os={
'code': facts.get('ansible_system', '')+' '+facts.get('ansible_distribution', '')+' '+facts.get('ansible_distribution_release', '')+' '+facts.get('ansible_distribution_version', ''), 'code': facts.get('ansible_system', '')+' '+facts.get('ansible_distribution', '')+' '+facts.get('ansible_distribution_release', '')+' '+facts.get('ansible_distribution_version', ''),
'name': facts.get('ansible_system', ''), 'name': facts.get('ansible_system', ''),
}, },
# privateIPs=facts[''], # privateIPs=facts[''],
# privateDNS=facts[''], # privateDNS=facts[''],
publicIPs=facts.get('ansible_all_ipv4_addresses', '')+facts.get('ansible_all_ipv6_addresses', ''), publicIPs=facts.get('ansible_all_ipv4_addresses', '')+facts.get('ansible_all_ipv6_addresses', ''),
...@@ -357,7 +365,7 @@ class ActionModule(object): ...@@ -357,7 +365,7 @@ class ActionModule(object):
'alerts': self.alerts, 'alerts': self.alerts,
'users': self.users, 'users': self.users,
'notifications': self.notifications, 'notifications': self.notifications,
} }
json.dump(cache, cache_file) json.dump(cache, cache_file)
def cache_reset(self): def cache_reset(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment