freeipa: support for host vars (#34535)

Adds method to return host vars related to FreeIPA hostname.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2018-01-15 13:57:30 +05:30 committed by GitHub
parent 48ecbb8fb9
commit 191b934dbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,8 +3,9 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
import argparse import argparse
from ipalib import api
import json import json
from ipalib import api, errors
from six import u
def initialize(): def initialize():
@ -72,25 +73,29 @@ def parse_args():
return parser.parse_args() return parser.parse_args()
def print_host(host): def get_host_attributes(api, host):
''' """
This function is really a stub, it could return variables to be used in
a playbook. However, at this point there are no variables stored in
FreeIPA/IPA.
This function expects one string, this hostname to lookup variables for. This function expects one string, this hostname to lookup variables for.
''' Args:
api: FreeIPA API Object
host: Name of Hostname
print(json.dumps({})) Returns: Dict of Host vars if found else None
"""
return None try:
result = api.Command.host_show(u(host))['result']
if 'usercertificate' in result:
del result['usercertificate']
return json.dumps(result, indent=1)
except errors.NotFound as e:
return {}
if __name__ == '__main__': if __name__ == '__main__':
args = parse_args() args = parse_args()
api = initialize()
if args.host: if args.host:
print_host(args.host) print(get_host_attributes(api, args.host))
elif args.list: elif args.list:
api = initialize()
list_groups(api) list_groups(api)