Port setup module to use the common module base

reviewable/pr18780/r1
Michael DeHaan 13 years ago
parent 2105418b73
commit 0b909b103d

38
setup

@ -598,31 +598,12 @@ def ansible_facts():
# ===========================================
# load config & template variables
def run_setup(module):
if len(sys.argv) == 1:
sys.exit(1)
argfile = sys.argv[1]
if not os.path.exists(argfile):
sys.exit(1)
setup_options = open(argfile).read().strip()
try:
setup_options = json.loads(setup_options)
except:
list_options = shlex.split(setup_options)
setup_options = {}
for opt in list_options:
(k,v) = opt.split("=")
setup_options[k]=v
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with %s' % setup_options)
facts = ansible_facts()
# Get some basic facts in case facter or ohai are not installed
for (k, v) in ansible_facts().items():
for (k, v) in facts.items():
setup_options["ansible_%s" % k] = v
# if facter is installed, and we can use --json because
@ -666,5 +647,16 @@ setup_result['ansible_facts'] = setup_options
# hack to keep --verbose from showing all the setup module results
setup_result['verbose_override'] = True
print json.dumps(setup_result)
return setup_result
def main():
module = AnsibleModule(
argument_spec = dict()
)
data = run_setup(module)
module.exit_json(**data)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()

Loading…
Cancel
Save