Ejemplo n.º 1
0
def main():
    argument_spec = f5_argument_spec()

    lb_method_choices = [
        'return_to_dns', 'null', 'round_robin', 'ratio', 'topology',
        'static_persist', 'global_availability', 'vs_capacity', 'least_conn',
        'lowest_rtt', 'lowest_hops', 'packet_rate', 'cpu', 'hit_ratio', 'qos',
        'bps', 'drop_packet', 'explicit_ip', 'connection_rate', 'vs_score'
    ]
    meta_args = dict(lb_method=dict(type='str',
                                    required=True,
                                    choices=lb_method_choices),
                     wide_ip=dict(type='str', required=True))
    argument_spec.update(meta_args)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    if not bigsuds_found:
        module.fail_json(msg="the python bigsuds module is required")

    server = module.params['server']
    server_port = module.params['server_port']
    user = module.params['user']
    password = module.params['password']
    wide_ip = module.params['wide_ip']
    lb_method = module.params['lb_method']
    validate_certs = module.params['validate_certs']

    result = {'changed': False}  # default

    try:
        api = bigip_api(server,
                        user,
                        password,
                        validate_certs,
                        port=server_port)

        if not wide_ip_exists(api, wide_ip):
            module.fail_json(msg="wide ip %s does not exist" % wide_ip)

        if lb_method is not None and lb_method != get_wide_ip_lb_method(
                api, wide_ip):
            if not module.check_mode:
                set_wide_ip_lb_method(api, wide_ip, lb_method)
                result = {'changed': True}
            else:
                result = {'changed': True}

    except Exception:
        e = get_exception()
        module.fail_json(msg="received exception: %s" % e)

    module.exit_json(**result)
Ejemplo n.º 2
0
def main():
    argument_spec = f5_argument_spec()

    lb_method_choices = ['return_to_dns', 'null', 'round_robin',
                                    'ratio', 'topology', 'static_persist', 'global_availability',
                                    'vs_capacity', 'least_conn', 'lowest_rtt', 'lowest_hops',
                                    'packet_rate', 'cpu', 'hit_ratio', 'qos', 'bps',
                                    'drop_packet', 'explicit_ip', 'connection_rate', 'vs_score']
    meta_args = dict(
        lb_method = dict(type='str', required=True, choices=lb_method_choices),
        wide_ip = dict(type='str', required=True)
    )
    argument_spec.update(meta_args)

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True
    )

    if not bigsuds_found:
        module.fail_json(msg="the python bigsuds module is required")

    server = module.params['server']
    server_port = module.params['server_port']
    user = module.params['user']
    password = module.params['password']
    wide_ip = module.params['wide_ip']
    lb_method = module.params['lb_method']
    validate_certs = module.params['validate_certs']

    result = {'changed': False}  # default

    try:
        api = bigip_api(server, user, password, validate_certs, port=server_port)

        if not wide_ip_exists(api, wide_ip):
            module.fail_json(msg="wide ip %s does not exist" % wide_ip)

        if lb_method is not None and lb_method != get_wide_ip_lb_method(api, wide_ip):
            if not module.check_mode:
                set_wide_ip_lb_method(api, wide_ip, lb_method)
                result = {'changed': True}
            else:
                result = {'changed': True}

    except Exception:
        e = get_exception()
        module.fail_json(msg="received exception: %s" % e)

    module.exit_json(**result)
Ejemplo n.º 3
0
def main():
    argument_spec = f5_argument_spec()

    meta_args = dict(
        state=dict(type='str', default='present', choices=['present', 'absent', 'enabled', 'disabled']),
        host=dict(type='str', default=None, aliases=['address']),
        port=dict(type='int', default=None),
        virtual_server_name=dict(type='str', required=True),
        virtual_server_server=dict(type='str', required=True)
    )
    argument_spec.update(meta_args)

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True
    )

    if not bigsuds_found:
        module.fail_json(msg="the python bigsuds module is required")

    server = module.params['server']
    server_port = module.params['server_port']
    validate_certs = module.params['validate_certs']
    user = module.params['user']
    password = module.params['password']
    virtual_server_name = module.params['virtual_server_name']
    virtual_server_server = module.params['virtual_server_server']
    state = module.params['state']
    address = module.params['host']
    port = module.params['port']

    result = {'changed': False}  # default

    try:
        api = bigip_api(server, user, password, validate_certs, port=server_port)

        if state == 'absent':
            if virtual_server_exists(api, virtual_server_name, virtual_server_server):
                if not module.check_mode:
                    remove_virtual_server(api, virtual_server_name, virtual_server_server)
                    result = {'changed': True}
                else:
                    # check-mode return value
                    result = {'changed': True}
        elif state == 'present':
            if virtual_server_name and virtual_server_server and address and port:
                if not virtual_server_exists(api, virtual_server_name, virtual_server_server):
                    if not module.check_mode:
                        if server_exists(api, virtual_server_server):
                            add_virtual_server(api, virtual_server_name, virtual_server_server, address, port)
                            result = {'changed': True}
                        else:
                            module.fail_json(msg="server does not exist")
                    else:
                        # check-mode return value
                        result = {'changed': True}
                else:
                    # virtual server exists -- potentially modify attributes --future feature
                    result = {'changed': False}
            else:
                module.fail_json(msg="Address and port are required to create virtual server")
        elif state == 'enabled':
            if not virtual_server_exists(api, virtual_server_name, virtual_server_server):
                module.fail_json(msg="virtual server does not exist")
            if state != get_virtual_server_state(api, virtual_server_name, virtual_server_server):
                if not module.check_mode:
                    set_virtual_server_state(api, virtual_server_name, virtual_server_server, state)
                    result = {'changed': True}
                else:
                    result = {'changed': True}
        elif state == 'disabled':
            if not virtual_server_exists(api, virtual_server_name, virtual_server_server):
                module.fail_json(msg="virtual server does not exist")
            if state != get_virtual_server_state(api, virtual_server_name, virtual_server_server):
                if not module.check_mode:
                    set_virtual_server_state(api, virtual_server_name, virtual_server_server, state)
                    result = {'changed': True}
                else:
                    result = {'changed': True}

    except Exception:
        e = get_exception()
        module.fail_json(msg="received exception: %s" % e)

    module.exit_json(**result)
def main():
    argument_spec = f5_argument_spec()

    meta_args = dict(
        state=dict(type='str', default='present', choices=['present', 'absent', 'enabled', 'disabled']),
        host=dict(type='str', default=None, aliases=['address']),
        port=dict(type='int', default=None),
        virtual_server_name=dict(type='str', required=True),
        virtual_server_server=dict(type='str', required=True)
    )
    argument_spec.update(meta_args)

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True
    )

    if not bigsuds_found:
        module.fail_json(msg="the python bigsuds module is required")

    server = module.params['server']
    server_port = module.params['server_port']
    validate_certs = module.params['validate_certs']
    user = module.params['user']
    password = module.params['password']
    virtual_server_name = module.params['virtual_server_name']
    virtual_server_server = module.params['virtual_server_server']
    state = module.params['state']
    address = module.params['host']
    port = module.params['port']

    result = {'changed': False}  # default

    try:
        api = bigip_api(server, user, password, validate_certs, port=server_port)

        if state == 'absent':
            if virtual_server_exists(api, virtual_server_name, virtual_server_server):
                if not module.check_mode:
                    remove_virtual_server(api, virtual_server_name, virtual_server_server)
                    result = {'changed': True}
                else:
                    # check-mode return value
                    result = {'changed': True}
        elif state == 'present':
            if virtual_server_name and virtual_server_server and address and port:
                if not virtual_server_exists(api, virtual_server_name, virtual_server_server):
                    if not module.check_mode:
                        if server_exists(api, virtual_server_server):
                            add_virtual_server(api, virtual_server_name, virtual_server_server, address, port)
                            result = {'changed': True}
                        else:
                            module.fail_json(msg="server does not exist")
                    else:
                        # check-mode return value
                        result = {'changed': True}
                else:
                    # virtual server exists -- potentially modify attributes --future feature
                    result = {'changed': False}
            else:
                module.fail_json(msg="Address and port are required to create virtual server")
        elif state == 'enabled':
            if not virtual_server_exists(api, virtual_server_name, virtual_server_server):
                module.fail_json(msg="virtual server does not exist")
            if state != get_virtual_server_state(api, virtual_server_name, virtual_server_server):
                if not module.check_mode:
                    set_virtual_server_state(api, virtual_server_name, virtual_server_server, state)
                    result = {'changed': True}
                else:
                    result = {'changed': True}
        elif state == 'disabled':
            if not virtual_server_exists(api, virtual_server_name, virtual_server_server):
                module.fail_json(msg="virtual server does not exist")
            if state != get_virtual_server_state(api, virtual_server_name, virtual_server_server):
                if not module.check_mode:
                    set_virtual_server_state(api, virtual_server_name, virtual_server_server, state)
                    result = {'changed': True}
                else:
                    result = {'changed': True}

    except Exception:
        e = get_exception()
        module.fail_json(msg="received exception: %s" % e)

    module.exit_json(**result)