aruba / aoscx-ansible-collection

Ansible collections for AOS-CX switches 
48 stars 23 forks source link

aoscx_backup_config always returns the running-config #111

Open kikSaki opened 3 months ago

kikSaki commented 3 months ago

Hey,

in the aoscx_backup_config module there is an option to specify the config_name to backup, yet it always returns the running-config.

Collection: arubanetworks.aoscx 4.4.0

Ansible Version: ansible [core 2.16.7]

CX switch: Aruba CX 6200F, Version ArubaOS-CX ML.10.10.1060

This is my playbook:

---
- hosts: arubacx
  collections:
    - arubanetworks.aoscx
  vars:
    ansible_python_interpreter: /usr/bin/python3
  gather_facts: False
  tasks:
  - name: Copy Startup Config to local as JSON
    aoscx_backup_config:
      config_name: startup-config
      output_file: /path/to/file/startup-config.json

This was tested with the names of the startup-config and checkpoints, but it always returned the running-config

This is a part of the output from debug with -vvv:

changed: [aoscx_1] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "config_name": "startup-config",
            "config_type": "json",
            "output_file": "/path/to/file/startup-config.json",
            "remote_output_file_tftp_path": null,
            "sort_json": true,
            "vrf": null
        }
    }
}

I also tested the switch REST API with Postman using the API /fullconfigs/{name} and /configs/{name}.

Tested with https://<ip-address>/rest/v10.10/fullconfigs/startup-config which returns the correct configuration. https://<ip-address>/rest/v10.10/configs/startup-config returns the correct configuration as well.

Another nice thing would be to be able to save the CLI version of the config locally via API, or at least have the option to display it in the output for better readability without using SSH.

tchiapuziowong commented 3 months ago

Thank you @kikSaki for bringing this to our attention! I'll work on bringing this to our internal team and will update the issue when there's an update!

tchiapuziowong commented 3 months ago

@kikSaki can you also share which pyaoscx version you're using?

kikSaki commented 3 months ago

I'm pretty sure I'm on the latest pyaoscx version: 2.6.0 I can double check in in a few days.

kikSaki commented 3 months ago

I checked the pyaoscx version. pyaoscx: Version: 2.6.0

kikSaki commented 3 months ago

I checked the pyaoscx code and possibly found where the problem is.

In the file pyaoscx/configuration.py in the function backup_configuration() when doing a local backup the following function is called: config_json = self.get_full_config()

The function defaults to running config since it doesn't receive an input: def get_full_config(self, config_name="running-config"):

So when doing backups locally it should be: File: pyaoscx/configuration.py at the end of function: backup_configuration()

        else:
            config_json = self.get_full_config(config_name)
            with open(output_file, "w") as to_file:
                formatted_file = json.dumps(config_json, indent=4)
                to_file.write(formatted_file)

            success = True