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)))
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 #3
0
def main():
    argument_spec = ecs_argument_spec()
    argument_spec.update(
        dict(
            group_name=dict(type='str', aliases=['name']),
            lang=dict(type='str'),
            state=dict(default='present', choices=['present', 'absent']),
        ))

    module = AnsibleModule(argument_spec=argument_spec)

    if HAS_FOOTMARK is False:
        module.fail_json(msg='footmark required for the module ali_dns_group.')

    dns_conn = dns_connect(module)

    # Get values of variable
    state = module.params['state']
    group_name = module.params['group_name']
    changed = False

    dns_group = dns_group_exists(module, dns_conn, group_name)

    if state == 'absent':
        if not dns_group:
            module.exit_json(changed=changed, groups={})
        try:
            module.exit_json(changed=dns_group.delete(), groups={})
        except DNSResponseError as ex:
            module.fail_json(
                msg='Unable to delete dns group{0}, error: {1}'.format(
                    dns_group.id, ex))

    if not dns_group:
        params = module.params
        try:
            dns_group = dns_conn.add_domain_group(**params)
            if dns_group:
                changed = True
            module.exit_json(changed=changed, groups=dns_group.get().read())
        except DNSResponseError as e:
            module.fail_json(
                msg='Unable to create dns group, error: {0}'.format(e))

    module.exit_json(changed=changed, groups=dns_group.read())
def main():
    argument_spec = ecs_argument_spec()
    argument_spec.update(
        dict(domain_name=dict(type='str', aliases=['name'], required=True),
             group_name=dict(type='str'),
             lang=dict(type='str'),
             resource_group_id=dict(type='str'),
             remark=dict(type='str'),
             state=dict(default='present', choices=['present', 'absent']),
             user_client_ip=dict(type='str')))

    module = AnsibleModule(argument_spec=argument_spec)

    if HAS_FOOTMARK is False:
        module.fail_json(
            msg='footmark required for the module ali_dns_domain.')

    dns_conn = dns_connect(module)

    # Get values of variable
    state = module.params['state']
    domain_name = module.params['domain_name']
    remark = module.params['remark']
    group_name = module.params['group_name']
    changed = False

    # Check if VPC exists
    dns = dns_exists(module, dns_conn, domain_name)

    if state == 'absent':
        if not dns:
            module.exit_json(changed=changed, dns={})
        try:
            module.exit_json(changed=dns.delete(), dns={})
        except DNSResponseError as ex:
            module.fail_json(
                msg='Unable to delete dns {0}, error: {1}'.format(dns.id, ex))

    if not dns:
        params = module.params
        try:
            dns = dns_conn.add_domain(**params)
            if dns:
                changed = True
        except DNSResponseError as e:
            module.fail_json(msg='Unable to create dns, error: {0}'.format(e))

    if domain_name and group_name:
        try:
            res = dns.change_domain_group(group_name=group_name,
                                          domain_name=domain_name)
            if res:
                changed = True
        except DNSResponseError as e:
            module.fail_json(
                msg='Unable to change domain group, error: {0}'.format(e))

    if remark:
        try:
            res = dns.modify_remark(remark=remark)
            if res:
                changed = True
        except DNSResponseError as e:
            module.fail_json(
                msg='Unable to modify dns remark, error: {0}'.format(e))
    module.exit_json(changed=changed, dns=dns.get().read())