Custom network OS module

Hi everyone!

I was recently charged to automate my company’s network with Ansible. We mainly use EXTREME ERS devices, which are not supported by any library, therefore I’m developping my own network module in order to support this OS.

I’m new to ansible module developping ( and ansible in general ) so there might be some misunderstandings on my side about how all of this should work, but for the moment this is what I’ve done :

  • I created a python script ( ERS_Connection.py ) that connects to my ERS device with netmiko and allows me to send commands to my device.
  • Now, I’m trying to develop a simple module ( command.py ) in order to be able to use this script via playbooks ( just as the cisco.ios.ios_command module ).

Here is the tree of my collection :
ers
│ │ │ ├── docs
│ │ │ ├── galaxy.yml
│ │ │ ├── meta
│ │ │ │ └── runtime.yml
│ │ │ ├── plugins
│ │ │ │ ├── cliconf
│ │ │ │ │ └── ers.py
│ │ │ │ ├── modules
│ │ │ │ │ ├── command.py
│ │ │ │ │ ├── gather_info.py
│ │ │ │ │ └── save_config_tftp.py
│ │ │ │ ├── module_utils
│ │ │ │ │ └── ERS_Connection.py
│ │ │ │ ├── README.md
│ │ │ │ └── terminal
│ │ │ │ └── ers.py
│ │ │ ├── README.md
│ │ │ └── roles

My question is how am I supposed to get the information about the current host inside of my command.py module, in order to pass it as argument to my python script?

Inside of the command.py file it should look something like this :

from my_custom_script import ERS_Connection

def run_module():
    module_args = dict(
        command=dict(type='str', required=True)
    )

    module = AnsibleModule(
            argument_spec=module_args,   
            supports_check_mode=True
    )
    result = dict(changed = False)

    host = module.get_current_host_ip() 
    # This is the part I'm trying to figure out
    # How do I get the information about the host?
    
    connection = ERS_Connection(host)
    connection.send_command(module.params["command"])
    connection.disconnect()

    module.exit_json(**result)

Thanks for any help!