From 8062b9c0f3ac1fb0edd0f353d26a90097f1897d3 Mon Sep 17 00:00:00 2001 From: Simon Dodsley Date: Fri, 8 Mar 2019 16:33:00 -0500 Subject: [PATCH] Update purefa_facts to collect admin accounts (#52856) --- .../storage/purestorage/purefa_facts.py | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/storage/purestorage/purefa_facts.py b/lib/ansible/modules/storage/purestorage/purefa_facts.py index 970409452b..8dc17c5ecd 100644 --- a/lib/ansible/modules/storage/purestorage/purefa_facts.py +++ b/lib/ansible/modules/storage/purestorage/purefa_facts.py @@ -30,7 +30,7 @@ options: - When supplied, this argument will define the facts to be collected. Possible values for this include all, minimum, config, performance, capacity, network, subnet, interfaces, hgroups, pgroups, hosts, - volumes, snapshots, pods, vgroups, offload and apps. + admins, volumes, snapshots, pods, vgroups, offload and apps. required: false default: minimum extends_documentation_fragment: @@ -352,6 +352,7 @@ def generate_default_dict(array): default_facts['pods'] = len(array.list_pods()) default_facts['connection_key'] = array.get(connection_key=True)['connection_key'] hosts = array.list_hosts() + admins = array.list_admins() snaps = array.list_volumes(snap=True, pending=True) pgroups = array.list_pgroups(pending=True) hgroups = array.list_hgroups() @@ -369,6 +370,7 @@ def generate_default_dict(array): default_facts['snapshots'] = len(snaps) default_facts['protection_groups'] = len(pgroups) default_facts['hostgroups'] = len(hgroups) + default_facts['admins'] = len(admins) return default_facts @@ -403,6 +405,7 @@ def generate_perf_dict(array): def generate_config_dict(array): config_facts = {} + api_version = array._list_available_rest_versions() # DNS config_facts['dns'] = array.get_dns() # SMTP @@ -411,7 +414,18 @@ def generate_config_dict(array): config_facts['snmp'] = array.list_snmp_managers() # DS config_facts['directory_service'] = array.get_directory_service() - config_facts['directory_service'].update(array.get_directory_service(groups=True)) + if S3_REQUIRED_API_VERSION in api_version: + config_facts['directory_service_roles'] = {} + roles = array.list_directory_service_roles() + for role in range(0, len(roles)): + role_name = roles[role]['name'] + config_facts['directory_service_roles'][role_name] = { + 'group': roles[role]['group'], + 'group_base': roles[role]['group_base'], + } + config_facts['directory_service'].update(array.list_directory_service_roles()) + else: + config_facts['directory_service'].update(array.get_directory_service(groups=True)) # NTP config_facts['ntp'] = array.get(ntpserver=True)['ntpserver'] # SYSLOG @@ -432,9 +446,24 @@ def generate_config_dict(array): config_facts['scsi_timeout'] = array.get(scsi_timeout=True)['scsi_timeout'] # SSL config_facts['ssl_certs'] = array.get_certificate() + # Global Admin settings + if S3_REQUIRED_API_VERSION in api_version: + config_facts['global_admin'] = array.get_global_admin_attributes() return config_facts +def generate_admin_dict(array): + admin_facts = {} + admins = array.list_admins() + for admin in range(0, len(admins)): + admin_name = admins[admin]['name'] + admin_facts[admin_name] = { + 'type': admins[admin]['type'], + 'role': admins[admin]['role'], + } + return admin_facts + + def generate_subnet_dict(array): sub_facts = {} subnets = array.list_subnets() @@ -700,8 +729,8 @@ def main(): subset = [test.lower() for test in module.params['gather_subset']] valid_subsets = ('all', 'minimum', 'config', 'performance', 'capacity', 'network', 'subnet', 'interfaces', 'hgroups', 'pgroups', - 'hosts', 'volumes', 'snapshots', 'pods', 'vgroups', - 'offload', 'apps') + 'hosts', 'admins', 'volumes', 'snapshots', 'pods', + 'vgroups', 'offload', 'apps') subset_test = (test in valid_subsets for test in subset) if not all(subset_test): module.fail_json(msg="value must gather_subset must be one or more of: %s, got: %s" @@ -735,6 +764,8 @@ def main(): facts['pgroups'] = generate_pgroups_dict(array) if 'pods' in subset or 'all' in subset: facts['pods'] = generate_pods_dict(array) + if 'admins' in subset or 'all' in subset: + facts['admins'] = generate_admin_dict(array) if 'vgroups' in subset or 'all' in subset: facts['vgroups'] = generate_vgroups_dict(array) if 'offload' in subset or 'all' in subset: