예제 #1
0
def main():
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            name=dict(required=True, type='str'),
            pwd=dict(required=False, default=None, type='str', no_log='True'),
            priv=dict(required=False,
                      default="read-only",
                      choices=["admin", "read-only", "user"],
                      type='str'),
            state=dict(required=False,
                       default="present",
                       choices=["present", "absent"],
                       type='str'),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)),
        supports_check_mode=True)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = setup(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #2
0
def main():
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            server_id=dict(required=False, type='int', default=1),
            chassis_id=dict(required=False, type='int', default=1),
            state=dict(required=False,
                       type='str',
                       choices=["on", "shutdown", "off", "reset", "boot"]),
            locator_led=dict(required=False, type='str', choices=["on",
                                                                  "off"]),
            timeout=dict(type='int', default=60),
            interval=dict(type='int', default=5),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)),
        supports_check_mode=True)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = setup(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #3
0
def main():
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            enabled=dict(required=True, type='str', choices=["yes", "no"]),
            snmp_port=dict(required=False, type='int', default=161),
            community=dict(required=False, type='str', default=None),
            privilege=dict(required=False,
                           type='str',
                           default="disabled",
                           choices=["disabled", "limited", "full"]),
            trap_community=dict(required=False, type='str', default=None),
            sys_contact=dict(required=False, type='str', default=None),
            sys_location=dict(required=False, type='str', default=None),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)),
        supports_check_mode=False)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = snmp_setup(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #4
0
def main():
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            bios_settings=dict(required=True, type='list'),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)),
        supports_check_mode=True)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = bios_setup(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #5
0
def main():
    argument_spec = dict(
        ip=dict(type='str', required=True, aliases=['hostname']),
        username=dict(type='str', required=True),
        password=dict(type='str', required=True, no_log=True),
        port=dict(type='str'),
        secure=dict(type='str'),
        proxy=dict(type='str'),
        objects=dict(type='list'),
        json_config_file=dict(type='str'),
        state=dict(type='str',
                   choices=['present', 'absent'],
                   default='present'),
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
        required_one_of=[
            ['objects', 'json_config_file'],
        ],
        mutually_exclusive=[
            ['objects', 'json_config_file'],
        ],
    )
    imc = ImcConnection(module)
    imc.result = {}
    imc.login()

    err = False
    # note that all objects specified in the object list report a single result (including a single changed).
    imc.result['changed'] = False
    try:
        if module.params.get('objects'):
            objects = module.params['objects']
        else:
            # either objects or json_config_file will be specified, so if there is no objects option use a config file
            with open(module.params['json_config_file']) as f:
                objects = json.load(f)['objects']

        for managed_object in objects:
            traverse_objects(module, imc, managed_object)

    except Exception as e:
        err = True
        imc.result['msg'] = "setup error: %s " % str(e)

    finally:
        imc.logout()

    if err:
        module.fail_json(**imc.result)
    module.exit_json(**imc.result)
예제 #6
0
def main():
    from ansible.module_utils.basic import AnsibleModule
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            basedn=dict(required=False),
            domain=dict(required=False),
            encryption=dict(required=False, default=True, type='bool'),
            timeout=dict(required=False, default=60, type='int'),
            user_search_precedence=dict(required=False),
            bind_method=dict(required=False,
                             default='login-credentials',
                             type='str'),
            bind_dn=dict(required=False),
            ldap_password=dict(required=False),
            filter=dict(required=False, type='str'),
            attribute=dict(required=False, type='str'),
            group_attribute=dict(required=False, type='str'),
            group_nested_search=dict(required=False, type='str'),
            group_auth=dict(required=False, default=False, type='bool'),
            ldap_servers=dict(required=False, type='list'),
            locate_directory_using_dns=dict(required=False,
                                            default=False,
                                            type='bool'),
            dns_domain_source=dict(required=False,
                                   default='extracted-domain',
                                   type='str'),
            dns_search_domain=dict(required=False),
            dns_search_forest=dict(required=False),
            state=dict(required=True,
                       choices=['present', 'absent'],
                       type='str'),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)),
        supports_check_mode=True)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = setup(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #7
0
def main():
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            speed=dict(type='str', default='115200',
                       choices=["9600", "19200", "38400", "57600", "115200"]),
            server_id=dict(required=False, type='int', default=1),
            com_port=dict(type='str', default="com0",
                      choices=["com0", "com1"]),
            ssh_port=dict(type='int', default=2400),
            state=dict(required=False, default="present",
                       choices=["present", "absent"], type='str'),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None),
            starship_options=dict(required=False, type='dict', default=None)
        ),
        supports_check_mode=True
    )

    if module.param['ssh_port'] < 1025 or module.param['ssh_port'] > 65535: 
        module.fail_json(msg="ssh_port must be in range 1024-65535")

    conn = ImcConnection(module)
    server = conn.login()
    results, err = setup(server, module)
    conn.logout()
    if err:
        results["status"] = "error"
        module.fail_json(**results)
    else:
        results["msg"] = ""
        results["status"] = "ok"
    module.exit_json(**results)
예제 #8
0
def main():
    from ansible.module_utils.basic import AnsibleModule
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            strong_password=dict(required=False,
                                 default="disabled",
                                 choices=["enabled", "disabled"],
                                 type='str'),
            password_expiry_duration=dict(required=False,
                                          default=0,
                                          type='int'),
            password_history=dict(required=False,
                                  default=0,
                                  choices=[0, 1, 2, 3, 4, 5],
                                  type='int'),
            password_notification_period=dict(required=False,
                                              default=0,
                                              type='int'),
            password_grace_period=dict(required=False, default=0, type='int'),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str'),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)),
        supports_check_mode=True)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = setup(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #9
0
def main():
    from ansible.module_utils.basic import AnsibleModule
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            boot_devices=dict(required=True, type='list'),
            configured_boot_mode=dict(required=False,
                                      default="Legacy",
                                      choices=["Legacy", "None", "Uefi"],
                                      type='str'),
            reapply=dict(required=False,
                         default="no",
                         choices=["yes", "no"],
                         type="str"),
            reboot_on_update=dict(required=False,
                                  default="no",
                                  choices=["yes", "no"],
                                  type="str"),
            server_id=dict(required=False, default=1, type='int'),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)),
        supports_check_mode=True)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = boot_order_precision(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #10
0
def main():
    from ansible.module_utils.cisco_imc import ImcConnection
    from imcsdk.apis.server.inventory import inventory_get
    module = AnsibleModule(
        argument_spec=dict(
            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str', no_log=True),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None)
        ),
        supports_check_mode=False
    )

    conn = ImcConnection(module)
    server = conn.login()
    inventory = inventory_get(server)
    conn.logout()
    module.exit_json(ansible_facts=dict(cimc_inventory=inventory[server.ip]))
def main():
    from ansible.module_utils.cisco_imc import ImcConnection
    module = AnsibleModule(
        argument_spec=dict(
            boot_drive=dict(required=False, default=False, type='bool'),
            drive_group=dict(required=True, type='list'),
            controller_type=dict(required=False, default='SAS', type='str'),
            controller_slot=dict(required=True, type='str'),
            raid_level=dict(required=False,
                            default=0,
                            choices=[0, 1, 5, 6, 10, 50, 60],
                            type='int'),
            virtual_drive_name=dict(required=False, type='str'),
            access_policy=dict(required=False,
                               default="read-write",
                               choices=["blocked", "read-only", "read-write"],
                               type='str'),
            read_policy=dict(required=False,
                             default="no-read-ahead",
                             choices=["always-read-ahead", "no-read-ahead"],
                             type='str'),
            cache_policy=dict(required=False,
                              default="direct-io",
                              choices=["cached-io", "direct-io"],
                              type='str'),
            disk_cache_policy=dict(
                required=False,
                default="unchanged",
                choices=["disabled", "enabled", "unchanged"],
                type='str'),
            write_policy=dict(required=False,
                              default="Write Through",
                              choices=[
                                  "Always Write Back", "Write Back Good BBU",
                                  "Write Through", "always-write-back",
                                  "write-back-good-bbu", "write-through"
                              ],
                              type='str'),
            strip_size=dict(required=False,
                            default="64k",
                            choices=[
                                "1024k", "128k", "16k", "256k", "32k", "512k",
                                "64k", "8k"
                            ],
                            type='str'),
            size=dict(required=False, type='str'),
            admin_action=dict(required=False,
                              choices=["enable-self-encrypt"],
                              type='str'),
            state=dict(required=False,
                       default="present",
                       choices=["present", "absent"],
                       type='str'),
            server_id=dict(required=False, default=1, type='int'),

            # ImcHandle
            server=dict(required=False, type='dict'),

            # Imc server credentials
            ip=dict(required=False, type='str'),
            username=dict(required=False, default="admin", type='str'),
            password=dict(required=False, type='str'),
            port=dict(required=False, default=None),
            secure=dict(required=False, default=None),
            proxy=dict(required=False, default=None),

            # For debugging purposes
            print_exception=dict(required=False, default=False, type='bool')),
        supports_check_mode=True)

    conn = ImcConnection(module)
    server = conn.login()
    results, err = virtual_drive(server, module)
    conn.logout()
    if err:
        module.fail_json(**results)
    module.exit_json(**results)
예제 #12
0
def main():
    argument_spec = dict(
        ip=dict(type='str', required=True, aliases=['hostname']),
        username=dict(type='str', required=True),
        password=dict(type='str', required=True, no_log=True),
        port=dict(type='str'),
        secure=dict(type='str'),
        proxy=dict(type='str'),
        class_ids=dict(type='str'),
        distinguished_names=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
        mutually_exclusive=[
            ['class_ids', 'distinguished_names'],
        ],
    )

    # imcModule verifies imcmsdk is present and exits on failure.
    # Imports are below for imc object creation.
    imc = ImcConnection(module)
    imc.result = {}
    imc.login()

    query_result = {}
    import epdb
    # epdb.serve()
    try:
        if module.params['class_ids']:
            class_ids = [
                x.strip() for x in module.params['class_ids'].split(',')
            ]
            for class_id in class_ids:
                query_result[class_id] = []
                imc_mos = retrieve_class_id(class_id, imc)
                if imc_mos:
                    for imc_mo in imc_mos:
                        query_result[class_id].append(make_mo_dict(imc_mo))

            imc.result['objects'] = query_result

        elif module.params['distinguished_names']:
            distinguished_names = [
                x.strip()
                for x in module.params['distinguished_names'].split(',')
            ]
            for distinguished_name in distinguished_names:
                query_result[distinguished_name] = {}
                imc_mo = retrieve_distinguished_name(distinguished_name, imc)

                if imc_mo:
                    query_result[distinguished_name] = make_mo_dict(imc_mo)

            imc.result['objects'] = query_result

    except Exception as e:
        imc.result['msg'] = "setup error: %s " % str(e)
        module.fail_json(**imc.result)

    finally:
        imc.logout()

    module.exit_json(**imc.result)