Python ansible.module_utils.basic.AnsibleModule() Examples
The following are 30
code examples of ansible.module_utils.basic.AnsibleModule().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ansible.module_utils.basic
, or try the search function
.
Example #1
Source File: ali_ram_access_key_info.py From alibaba.alicloud with Apache License 2.0 | 6 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( user_name=dict(type='str', aliases=['name']) )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") try: access_key = [] for access in ram_connect(module).list_access_keys(**module.params): access_key.append(access.read()) module.exit_json(changed=False, access_keys=access_key) except Exception as e: module.fail_json(msg=str("Unable to list access_keys, error:{0}".format(e)))
Example #2
Source File: jenkins_update_center.py From cinch with GNU General Public License v3.0 | 6 votes |
def main(): module = AnsibleModule( argument_spec={ 'jenkins_home': {'default': '/var/lib/jenkins'}, 'update_center_id': {'required': True}, 'update_center_url': {'required': True} } ) update_ctr_config = os.path.join(module.params['jenkins_home'], 'hudson.model.UpdateCenter.xml') tree = ET.parse(update_ctr_config) if module.params['update_center_id'] == 'default': changed = set_default(tree, module.params['update_center_url']) else: changed = append(tree, module.params['update_center_id'], module.params['update_center_url']) if changed: tree.write(update_ctr_config, encoding='UTF-8') module.exit_json(changed=changed)
Example #3
Source File: glusterfs_check_containerized.py From ansible-redhat_openshift_utils with Apache License 2.0 | 6 votes |
def run_module(): '''Run this module''' module_args = dict( oc_bin=dict(type='path', required=True), oc_conf=dict(type='path', required=True), oc_namespace=dict(type='str', required=True), cluster_name=dict(type='str', required=True), exclude_node=dict(type='str', required=True), ) module = AnsibleModule( supports_check_mode=False, argument_spec=module_args ) oc_bin = module.params['oc_bin'] oc_conf = '--config={}'.format(module.params['oc_conf']) oc_namespace = '--namespace={}'.format(module.params['oc_namespace']) cluster_name = module.params['cluster_name'] exclude_node = module.params['exclude_node'] oc_exec = [oc_bin, oc_conf, oc_namespace] # create a nodes to find a pod on; We don't want to try to execute on a # pod running on a "NotReady" node or the inventory_hostname node because # the pods might not actually be alive. valid_nodes = get_valid_nodes(module, [oc_bin, oc_conf], exclude_node) # Need to find an alive pod to run gluster commands in. pod_name = select_pod(module, oc_exec, cluster_name, valid_nodes) check_volumes(module, oc_exec, pod_name) result = {'changed': False} module.exit_json(**result)
Example #4
Source File: ali_ram_policy_info.py From alibaba.alicloud with Apache License 2.0 | 6 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( name_prefix=dict(type='str')) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") name_prefix = module.params['name_prefix'] try: policies = [] for policy in ram_connect(module).list_policies(): if name_prefix and not policy.name.startswith(name_prefix): continue policies.append(policy.read()) module.exit_json(changed=False, policies=policies) except Exception as e: module.fail_json(msg=str("Unable to list groups, error:{0}".format(e)))
Example #5
Source File: ali_rds_account_info.py From alibaba.alicloud with Apache License 2.0 | 6 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( db_instance_id=dict(type='str', aliases=['instance_id'], required=True), name_prefix=dict(type='str') )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json("Package 'footmark' required for this module.") # Get values of variable db_instance_id = module.params['db_instance_id'] name_prefix = module.params['name_prefix'] result = [] try: rds = rds_connect(module) for account in rds.describe_accounts(db_instance_id=db_instance_id): if name_prefix and not account.name.startswith(name_prefix): continue result.append(account.read()) module.exit_json(changed=False, rds_accounts=result) except Exception as e: module.fail_json(msg="Unable to describe rds accounts, and got an error: {0}.".format(e))
Example #6
Source File: ali_ram_user_info.py From alibaba.alicloud with Apache License 2.0 | 6 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( name_prefix=dict(type='str')), user_ids=dict(type='list', elements='str') ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") name_prefix = module.params['name_prefix'] user_ids = module.params['user_ids'] try: users = [] for user in ram_connect(module).list_users(): if name_prefix and not user.name.startswith(name_prefix): continue if user_ids and user.user_id not in user_ids: continue users.append(user.read()) module.exit_json(changed=False, users=users) except Exception as e: module.fail_json(msg=str("Unable to list users, error:{0}".format(e)))
Example #7
Source File: ali_ram_group_info.py From alibaba.alicloud with Apache License 2.0 | 6 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( name_prefix=dict(type='str')) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") name_prefix = module.params['name_prefix'] try: groups = [] for group in ram_connect(module).list_groups(): if name_prefix and not group.name.startswith(name_prefix): continue groups.append(group.read()) module.exit_json(changed=False, groups=groups) except Exception as e: module.fail_json(msg=str("Unable to list groups, error:{0}".format(e)))
Example #8
Source File: vmanage_central_policy_facts.py From python-viptela with GNU General Public License v3.0 | 5 votes |
def run_module(): # define available arguments/parameters a user can pass to the module argument_spec = vmanage_argument_spec() argument_spec.update(type=dict(type='str', required=False, default='all'), ) # seed the result dict in the object # we primarily care about changed and state # change is if this module effectively modified the target # state will include any data that you want your module to pass back # for consumption, for example, in a subsequent task result = dict( changed=False, original_message='', message='' ) # the AnsibleModule object will be our abstraction working with Ansible # this includes instantiation, a couple of common attr would be the # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, ) vmanage = Vmanage(module) policy_data = PolicyData(vmanage.auth, vmanage.host) vmanage.result['central_policy'] = policy_data.export_central_policy_list() vmanage.exit_json(**vmanage.result)
Example #9
Source File: ali_route_entry_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( vrouter_id=dict(type='str', required=True, aliases=['id']), route_table_id=dict(type='str') ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") result = [] vrouter_id = module.params['vrouter_id'] route_table_id = module.params['route_table_id'] try: vpc_conn = vpc_connect(module) # list all route entries in vrouter if vrouter_id: vrouter_entries = vpc_conn.get_all_route_entries(router_id=vrouter_id, route_table_id=route_table_id) for vrouter_entry in vrouter_entries: result.append(get_info(vrouter_entry)) except Exception as e: module.fail_json(msg="Unable to describe vrouter entries, and got an error: {0}.".format(e)) module.exit_json(changed=False, vrouter_id=vrouter_id, vroute_entries=result, total=len(result))
Example #10
Source File: ali_vpc_tag.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( state=dict(default='present', choices=['present', 'absent']), resource_ids=dict(type='list', elements='str', required=True), resource_type=dict(type='str', default='vpc', choices=['vpc', 'vswitch', 'eip']), tags=dict(type='dict') )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg='footmark required for the module ali_vpc_tag.') vpc_conn = vpc_connect(module) if module.params['resource_type'] == 'vpc': module.params['resource_type'] = 'VPC' resources = vpc_exists(module, vpc_conn) elif module.params['resource_type'] == 'vswitch': module.params['resource_type'] = 'VSWITCH' resources = vsw_exists(module, vpc_conn) else: module.params['resource_type'] = 'EIP' resources = eip_exists(module, vpc_conn) if not resources: module.fail_json(msg='No matching resource was found based on the IDS provided.') # Get values of variable tags = module.params['tags'] if module.params['state'] == "present": changed = vpc_conn.tag_resources(resource_ids=module.params['resource_ids'], tags=tags, resource_type=module.params['resource_type']) else: changed = vpc_conn.un_tag_resources(resource_ids=module.params['resource_ids'], tags=tags, resource_type=module.params['resource_type']) result = [] for resource in resources: result.append({'tags': resource.read()['tags']}) module.exit_json(changed=changed, tags=result)
Example #11
Source File: ali_dns_group_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( name_prefix=dict(type='str'), group_id=dict(type='str', aliases=['id']), ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") name_prefix = module.params['name_prefix'] group_id = module.params['group_id'] try: groups = [] ids = [] for _dns in dns_connect(module).describe_domain_groups(): if name_prefix and not _dns.name.startswith(name_prefix): continue if group_id and _dns.id != group_id: continue groups.append(_dns.read()) ids.append(_dns.id) module.exit_json(changed=False, groups=groups, ids=ids) except Exception as e: module.fail_json(msg=str("Unable to get dns group, error:{0}".format(e)))
Example #12
Source File: ali_oss_bucket_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = oss_bucket_argument_spec() argument_spec.update( dict( bucket=dict(aliases=["name"]), bucket_prefix=dict(type="str") ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") try: oss_service = oss_service_connect(module) keys = oss_service.list_buckets(prefix=module.params['bucket_prefix'], max_keys=200) buckets = [] bucket_names = [] for name in keys: module.params['bucket'] = name bucket = oss_bucket_connect(module) buckets.append(get_info(bucket)) bucket_names.append(bucket.name) module.exit_json(changed=False, bucket_names=bucket_names, buckets=buckets, total=len(buckets)) except Exception as e: module.fail_json(msg="Unable to describe buckets, and got an error: {0}.".format(e))
Example #13
Source File: ali_rds_backup.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( state=dict(default='present', choices=['present', 'absent']), db_instance_id=dict(type='str', aliases=['instance_id'], required=True), db_name=dict(type='list', elements='str'), backup_id=dict(type='list', elements='str'), backup_method=dict(type='str', default='Physical'), backup_strategy=dict(type='str'), backup_type=dict(type='str', default='Auto') )) module = AnsibleModule(argument_spec=argument_spec) rds = rds_connect(module) if HAS_FOOTMARK is False: module.fail_json(msg="Footmark required for this module") # Get values of variable state = module.params['state'] backup_id = module.params['backup_id'] db_name = module.params['db_name'] if backup_id: module.params['backup_id'] = ','.join(backup_id) if db_name: module.params['db_name'] = ','.join(db_name) if state == 'absent': try: changed = rds.delete_backup(**module.params) module.exit_json(changed=changed, backup={}) except Exception as e: module.fail_json(msg=str("Unable to delete backup error:{0}".format(e))) if state == 'present': try: create_backup = rds.create_backup(**module.params) module.exit_json(changed=True, backup=create_backup.read()) except Exception as e: module.fail_json(msg=str("Unable to create backup error:{0}".format(e)))
Example #14
Source File: ali_slb_tag.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( state=dict(default='present', choices=['present', 'absent']), resource_ids=dict(type='list', elements='str'), resource_type=dict(type='str', default='instance'), tags=dict(type='dict') )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg='footmark required for the module ali_slb_tag.') slb_conn = slb_connect(module) slbs = slb_exists(module, slb_conn) if not slbs: module.fail_json(msg='No matching SLB was found based on the IDS provided.') # Get values of variable tags = module.params['tags'] if module.params['state'] == "present": slb_changed = slb_conn.tag_resources(resource_ids=module.params['resource_ids'], tags=tags, resource_type=module.params['resource_type']) else: slb_changed = slb_conn.untag_resources(resource_ids=module.params['resource_ids'], tags=tags, resource_type=module.params['resource_type']) result = [] for slb in slbs: result.append(slb.get().read()) module.exit_json(changed=slb_changed, tags=result)
Example #15
Source File: ali_rds_instance_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( name_prefix=dict(type='str'), db_instance_ids=dict(type='list', elements='str'), tags=dict(type='dict') )) module = AnsibleModule(argument_spec=argument_spec) rds = rds_connect(module) name_prefix = module.params['name_prefix'] db_instance_ids = module.params['db_instance_ids'] if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") result = [] try: for rds_instance in rds.describe_db_instances(**module.params): if name_prefix and not rds_instance.read()['name'].startswith(name_prefix): continue if db_instance_ids and rds_instance.read()['id'] not in db_instance_ids: continue result.append(rds_instance.get().read()) module.exit_json(changed=False, instances=result) except Exception as e: module.fail_json(msg="Unable to describe rds db instance, and got an error: {0}.".format(e))
Example #16
Source File: ali_rds_backup_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( db_instance_id=dict(type='str', aliases=['instance_id'], required=True), backup_id=dict(type='str'), backup_status=dict(type='str', choice=['Success', 'Failed']), backup_mode=dict(type='str', choice=['Automated', 'Manual']) )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") result = [] backup_status = module.params['backup_status'] backup_mode = module.params['backup_mode'] try: rds = rds_connect(module) for backup in rds.describe_backups(**module.params): if backup_status and backup.status.lower() != backup_status.lower(): continue if backup_mode and backup.mode.lower() != backup_status.lower(): continue result.append(backup.read()) except Exception as e: module.fail_json(msg="Unable to describe rds backup, and got an error: {0}.".format(e)) module.exit_json(changed=True, backups=result)
Example #17
Source File: ali_rds_database_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( db_instance_id=dict(type='str', aliases=['instance_id'], required=True), name_prefix=dict(type='str'), db_status=dict(type='str', aliases=['status']) )) module = AnsibleModule(argument_spec=argument_spec) rds = rds_connect(module) name_prefix = module.params['name_prefix'] db_status = module.params['db_status'] if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") result = [] try: for db in rds.describe_databases(**module.params): if name_prefix and not db.dbname.startswith(name_prefix): continue if db_status and db.dbstatus.lower() != db_status.lower(): continue result.append(db.read()) module.exit_json(changed=False, databases=result) except Exception as e: module.fail_json(msg="Unable to describe rds database, and got an error: {0}.".format(e))
Example #18
Source File: vmanage_local_policy_facts.py From python-viptela with GNU General Public License v3.0 | 5 votes |
def run_module(): # define available arguments/parameters a user can pass to the module argument_spec = vmanage_argument_spec() argument_spec.update(type=dict(type='str', required=False, default='all'), ) # seed the result dict in the object # we primarily care about changed and state # change is if this module effectively modified the target # state will include any data that you want your module to pass back # for consumption, for example, in a subsequent task result = dict( changed=False, original_message='', message='' ) # the AnsibleModule object will be our abstraction working with Ansible # this includes instantiation, a couple of common attr would be the # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, ) vmanage = Vmanage(module) policy_data = PolicyData(vmanage.auth, vmanage.host) vmanage.result['local_policy'] = policy_data.export_local_policy_list() vmanage.exit_json(**vmanage.result)
Example #19
Source File: vmanage_attachment_export.py From python-viptela with GNU General Public License v3.0 | 5 votes |
def run_module(): # define available arguments/parameters a user can pass to the module argument_spec = vmanage_argument_spec() argument_spec.update(file=dict(type='str', required=True), update=dict(type='bool', required=False, default=False), type=dict(type='str', required=False, choices=['feature', 'device'], default=None), name_list=dict(type='list', required=False, default=[]), ) # seed the result dict in the object # we primarily care about changed and state # change is if this module effectively modified the target # state will include any data that you want your module to pass back # for consumption, for example, in a subsequent task result = dict( changed=False, original_message='', message='' ) # the AnsibleModule object will be our abstraction working with Ansible # this includes instantiation, a couple of common attr would be the # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, ) vmanage = Vmanage(module) vmanage_files = Files(vmanage.auth, vmanage.host) vmanage_files.export_attachments_to_file(vmanage.params['file'], name_list=vmanage.params['name_list']) vmanage.exit_json(**vmanage.result)
Example #20
Source File: vmanage_fileupload.py From python-viptela with GNU General Public License v3.0 | 5 votes |
def run_module(): # define available arguments/parameters a user can pass to the module argument_spec = viptela_argument_spec() argument_spec.update(file=dict(type='str', required=True), ) # seed the result dict in the object # we primarily care about changed and state # change is if this module effectively modified the target # state will include any data that you want your module to pass back # for consumption, for example, in a subsequent task result = dict( changed=False, original_message='', message='' ) # the AnsibleModule object will be our abstraction working with Ansible # this includes instantiation, a couple of common attr would be the # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, ) viptela = viptelaModule(module) if not module.check_mode: response = viptela.request('/dataservice/system/device/fileupload', method='POST', files={'file': open(module.params['file'], 'rb')}, data={'validity': 'valid', 'upload': 'true'}, headers=None) viptela.result['msg'] = response.json['vedgeListUploadStatus'] if 'successfully' in response.json['vedgeListUploadStatus']: viptela.result['changed'] = True viptela.exit_json()
Example #21
Source File: ali_oss_object_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = oss_bucket_argument_spec() argument_spec.update(dict( bucket=dict(type='str', required=True), object=dict(type='str', aliases=['key', 'object_name']), )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") object_key = module.params['object'] objects = [] object_names = [] max_keys = 500 try: oss_bucket = oss_bucket_connect(module) while True: results = oss_bucket.list_objects(prefix=object_key, max_keys=max_keys) for obj in results: objects.append(get_info(obj)) object_names.append(obj.key) if len(results) < max_keys: break module.exit_json(changed=False, object_names=object_names, objects=objects, total=len(objects)) except Exception as e: module.fail_json(msg="Unable to describe bucket objects, and got an error: {0}".format(e))
Example #22
Source File: ali_slb_listener_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( listener_port=dict(type='int', required=True), load_balancer_id=dict(type='str', required=True, aliases=['lb_id']), listener_type=dict(type='str', required=True, choices=['http', 'https', 'tcp', 'udp']) )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") load_balancer_id = module.params['load_balancer_id'] listener_port = module.params['listener_port'] listener_type = module.params['listener_type'] try: slb = slb_connect(module) # check whether server load balancer exist or not laod_balancer = slb.describe_load_balancers(load_balancer_id=load_balancer_id) if laod_balancer and len(laod_balancer) == 1: # list load balancers listeners listener = slb.describe_load_balancer_listener_attribute(load_balancer_id, listener_port, listener_type) if listener is None: module.fail_json(msg="Unable to describe slb listeners, no listeners found") else: module.exit_json(changed=False, listener=get_info(listener)) else: module.fail_json(msg="Unable to describe slb listeners, invalid load balancer id") except Exception as e: module.fail_json(msg="Unable to describe slb listeners, and got an error: {0}.".format(e))
Example #23
Source File: _ali_oss_bucket_facts.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = oss_bucket_argument_spec() argument_spec.update( dict( bucket=dict(aliases=["name"]), bucket_prefix=dict(type="str") ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") try: oss_service = oss_service_connect(module) keys = oss_service.list_buckets(prefix=module.params['bucket_prefix'], max_keys=200) buckets = [] bucket_names = [] for name in keys: module.params['bucket'] = name bucket = oss_bucket_connect(module) buckets.append(get_info(bucket)) bucket_names.append(bucket.name) module.exit_json(changed=False, bucket_names=bucket_names, buckets=buckets, total=len(buckets)) except Exception as e: module.fail_json(msg="Unable to describe buckets, and got an error: {0}.".format(e))
Example #24
Source File: ali_oos_execution_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( filters=dict(type='dict'), name_prefix=dict(type='str', aliases=['name']), ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") executions = [] ids = [] name_prefix = module.params['name_prefix'] filters = module.params['filters'] if not filters: filters = {} try: for e in oos_connect(module).list_executions(**filters): if name_prefix and not str(e.name).startswith(name_prefix): continue executions.append(e.read()) ids.append(e.id) module.exit_json(changed=False, ids=ids, executions=executions) except Exception as e: module.fail_json(msg=str("Unable to get executions, error:{0}".format(e)))
Example #25
Source File: ali_dns_domain_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( domain_name=dict(type='str', aliases=['name']), filters=dict(type='dict') ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") filters = module.params['filters'] if not filters: filters = {} domain_name = module.params['domain_name'] try: dns = [] names = [] for _dns in dns_connect(module).describe_domains(**filters): if domain_name and _dns.domain_name != domain_name: continue dns.append(_dns.read()) names.append(_dns.domain_name) module.exit_json(changed=False, names=names, dns=dns) except Exception as e: module.fail_json(msg=str("Unable to get dns, error:{0}".format(e)))
Example #26
Source File: _alicloud_disk_facts.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( alicloud_zone=dict(aliases=['zone_id', 'zone']), disk_ids=dict(type='list', aliases=['ids']), disk_names=dict(type='list', aliases=['names']), ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg='footmark required for this module') ecs = ecs_connect(module) disks = [] disk_ids = [] ids = module.params['disk_ids'] names = module.params['disk_names'] zone_id = module.params['alicloud_zone'] if ids and (not isinstance(ids, list) or len(ids)) < 1: module.fail_json(msg='disk_ids should be a list of disk id, aborting') if names and (not isinstance(names, list) or len(names)) < 1: module.fail_json(msg='disk_names should be a list of disk name, aborting') if names: for name in names: for disk in ecs.get_all_volumes(zone_id=zone_id, volume_ids=ids, volume_name=name): disks.append(get_disk_info(disk)) disk_ids.append(disk.id) else: for disk in ecs.get_all_volumes(zone_id=zone_id, volume_ids=ids): disks.append(get_disk_info(disk)) disk_ids.append(disk.id) module.exit_json(changed=False, disk_ids=disk_ids, disks=disks, total=len(disks))
Example #27
Source File: ali_disk_info.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( filters=dict(type='dict'), name_prefix=dict(type='str'), tags=dict(type='dict') ) ) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg='footmark required for this module') ecs = ecs_connect(module) disks = [] disk_ids = [] filters = module.params['filters'] if not filters: filters = {} name_prefix = module.params['name_prefix'] tags = module.params['tags'] for disk in ecs.describe_disks(**filters): if name_prefix and not str(disk.name).startswith(name_prefix): continue if tags: flag = False for key, value in list(tags.items()): if key in list(disk.tags.keys()) and value == disk.tags[key]: flag = True if not flag: continue disks.append(disk.read()) disk_ids.append(disk.id) module.exit_json(changed=False, disk_ids=disk_ids, disks=disks, total=len(disks))
Example #28
Source File: custom_module_2.py From Mastering-Python-Networking-Second-Edition with MIT License | 5 votes |
def main(): module = AnsibleModule( argument_spec = dict( host = dict(required=True), username = dict(required=True), password = dict(required=True) ) ) device = module.params.get('host') username = module.params.get('username') password = module.params.get('password') url='http://' + host + '/ins' switchuser=username switchpassword=password myheaders={'content-type':'application/json-rpc'} payload=[ { "jsonrpc": "2.0", "method": "cli", "params": { "cmd": "show version", "version": 1.2 }, "id": 1 } ] response = requests.post(url,data=json.dumps(payload), headers=myheaders,auth=(switchuser,switchpassword)).json() version = response['result']['body']['sys_ver_str'] data = json.dumps({"version": version}) module.exit_json(changed=False, msg=str(data))
Example #29
Source File: _ali_rds_account_facts.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = ecs_argument_spec() argument_spec.update(dict( db_instance_id=dict(type='str', required=True), account_names=dict(type='list', aliases=['names']) )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json("Package 'footmark' required for this module.") # Get values of variable db_instance_id = module.params['db_instance_id'] names = module.params['account_names'] result = [] try: rds = rds_connect(module) if names and (not isinstance(names, list) or len(names)) < 1: module.fail_json(msg='account_name should be a list of account name, aborting') # fetch rds accounts by name if names: for name in names: rds_accounts = rds.list_account(db_instance_id=db_instance_id, account_name=name) if rds_accounts and len(rds_accounts) == 1: result.append(get_info(rds_accounts[0])) # fetch all rds accounts else: names = [] for account in rds.list_account(db_instance_id=db_instance_id): names.append(account.account_name) result.append(get_info(account)) module.exit_json(changed=False, account_names=names, rds_accounts=result, total=len(result)) except Exception as e: module.fail_json(msg="Unable to describe rds accounts, and got an error: {0}.".format(e))
Example #30
Source File: _ali_oss_object_facts.py From alibaba.alicloud with Apache License 2.0 | 5 votes |
def main(): argument_spec = oss_bucket_argument_spec() argument_spec.update(dict( bucket=dict(type='str', required=True), object=dict(type='str', aliases=['key', 'object_name']), )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") object_key = module.params['object'] objects = [] object_names = [] max_keys = 500 try: oss_bucket = oss_bucket_connect(module) while True: results = oss_bucket.list_objects(prefix=object_key, max_keys=max_keys) for obj in results: objects.append(get_info(obj)) object_names.append(obj.key) if len(results) < max_keys: break module.exit_json(changed=False, object_names=object_names, objects=objects, total=len(objects)) except Exception as e: module.fail_json(msg="Unable to describe bucket objects, and got an error: {0}".format(e))