Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aoscx_config is not failing in case of configuration error #24

Closed
ssasso opened this issue Jan 6, 2025 · 4 comments
Closed

aoscx_config is not failing in case of configuration error #24

ssasso opened this issue Jan 6, 2025 · 4 comments

Comments

@ssasso
Copy link

ssasso commented Jan 6, 2025

In case aoscx_config is supplied a config file with the src param, the playbook execution continues even if the source config file has invalid configuration in it.

I would have expected a module failure in case of invalid config, but this is not happening.

@ssasso
Copy link
Author

ssasso commented Jan 6, 2025

Quick&Dirty proposal:

The config is sent to the device here:

load_config(module, commands)

It would be possible to return from load_config the stdout/stderr of every command invocation (out and err) from here:

https://github.com/aruba/aoscx-ansible-role/blob/master/module_utils/aoscx.py#L104

and then:

if any of out (or err) contains the string ^Invalid input: (which is returned by the CLI in case of config command error) return an error instead of success - or, at least, return all the stdout/stderr to the user as a module output, and let the user decide what to do.

@jbemmel
Copy link

jbemmel commented Jan 6, 2025

def load_config(module, commands):
    '''
    Loads the configuration onto the switch
    '''
    rc, out, err = exec_command(module, 'configure terminal')
    if rc != 0:
        module.fail_json(msg='unable to enter configuration mode',
                         err=to_text(out, errors='surrogate_then_replace'))

    for command in to_list(commands):
        if command == 'end':
            continue
        rc, out, err = exec_command(module, command)
        if rc != 0 or 'Invalid input' in out:   <!-- ADD
            module.fail_json(msg=to_text(
                err or out, errors='surrogate_then_replace'), command=command, rc=rc) <!-- ADD 'out'

    exec_command(module, 'end')

@ssasso
Copy link
Author

ssasso commented Jan 6, 2025

def load_config(module, commands):
    '''
    Loads the configuration onto the switch
    '''
    rc, out, err = exec_command(module, 'configure terminal')
    if rc != 0:
        module.fail_json(msg='unable to enter configuration mode',
                         err=to_text(out, errors='surrogate_then_replace'))

    for command in to_list(commands):
        if command == 'end':
            continue
        rc, out, err = exec_command(module, command)
        if rc != 0 or 'Invalid input' in out:   <!-- ADD
            module.fail_json(msg=to_text(
                err, errors='surrogate_then_replace'), command=command, rc=rc)

    exec_command(module, 'end')

In this case, also out shall be reported, to simply identify where the wrong configuration is.

@alagoutte
Copy link

this ansible role is EOL, you need to ask on ansible aoscx collection -> https://github.com/aruba/aoscx-ansible-collection

@tchiapuziowong @Joe-Neville may be put this repo in read-only/ archived ?

@ssasso ssasso closed this as completed Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants