diff options
author | Abhijeet Kasurde <akasurde@redhat.com> | 2018-01-15 13:57:30 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-15 13:57:30 +0530 |
commit | 191b934dbd36f46169d2ad843550dbbdc07e8d7d (patch) | |
tree | fbbae75f93dad71e414b431bc569c7fa4c73ff43 /contrib | |
parent | 48ecbb8fb90080b4d1056bbb1dc2bfaddcf2c847 (diff) | |
download | ansible-191b934dbd36f46169d2ad843550dbbdc07e8d7d.tar.gz |
freeipa: support for host vars (#34535)
Adds method to return host vars related to FreeIPA hostname.
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/inventory/freeipa.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/contrib/inventory/freeipa.py b/contrib/inventory/freeipa.py index 20f5626aed..7efc05e3d8 100755 --- a/contrib/inventory/freeipa.py +++ b/contrib/inventory/freeipa.py @@ -3,8 +3,9 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) import argparse -from ipalib import api import json +from ipalib import api, errors +from six import u def initialize(): @@ -72,25 +73,29 @@ def parse_args(): return parser.parse_args() -def print_host(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. - +def get_host_attributes(api, host): + """ This function expects one string, this hostname to lookup variables for. - ''' + Args: + api: FreeIPA API Object + host: Name of Hostname - print(json.dumps({})) - - return None + Returns: Dict of Host vars if found else 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__': args = parse_args() + api = initialize() if args.host: - print_host(args.host) + print(get_host_attributes(api, args.host)) elif args.list: - api = initialize() list_groups(api) |