Skip to content

Instantly share code, notes, and snippets.

@vicenteg
Last active August 29, 2015 14:12
Show Gist options
  • Save vicenteg/da3c1b2dbc906c51cd8e to your computer and use it in GitHub Desktop.
Save vicenteg/da3c1b2dbc906c51cd8e to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# mapr_facts: get facts about a MapR cluster.
#
# Copyright 2014, Vince Gonzalez
# Vince Gonzalez <[email protected]>
#
# This software may be freely redistributed under the terms of the GNU
# general public license version 2.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
module: mapr_facts
short_description: get facts about a MapR Hadoop cluster
description:
- Get facts about a MapR Hadoop cluster
version_added: "1.0"
options:
requirements: this module should target a cluster node.
author: Vince Gonzalez
'''
try:
import json
except:
import simplejson as json
import os
import socket
def finish(m, facts_dict, changed, msg=""):
m.exit_json(changed=changed, ansible_facts=facts_dict, msg=msg)
def abort(m, msg=""):
m.fail_json(msg=msg)
def get_facts():
hostname = socket.gethostname()
facts = { "ansible_facts": dict() }
if os.path.exists("/opt/mapr/bin/maprcli"):
command = "/opt/mapr/bin/maprcli node list -filter hostname==%s -json" % hostname
p = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE)
output = p.communicate()[0]
data = json.loads(output)
facts["ansible_facts"] = data["data"][0]
return facts
def get_licenses():
command = "maprcli license list -json".split(" ")
p = subprocess.Popen(command, stdout=subprocess.PIPE)
output = p.communicate()[0]
print output
return json.loads(output)
def main():
module = AnsibleModule(
argument_spec=dict(),
supports_check_mode=False,
mutually_exclusive = [ ]
)
finish(module, changed=False, facts_dict=get_facts(), msg="foo")
from ansible.module_utils.basic import *
main()
- hosts: all
tasks:
- name: mapr facts
mapr_facts:
# see the mapr_facts
- debug: var=ansible_facts
# check that normal ansible facts remain
- debug: var=ansible_devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment