Created
December 6, 2018 18:21
-
-
Save Qalthos/05af40490808fc3c4eef3b5952d1cdcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals, print_function | |
from ansible.module_utils.basic import AnsibleModule, return_values | |
DOCUMENTATION = ''' | |
--- | |
module: napalm_cli | |
author: "Charlie Allom" | |
version_added: "2.2" | |
short_description: "Executes network device CLI commands and returns response using NAPALM" | |
description: | |
- "Executes network device CLI commands and returns response using NAPALM" | |
options: | |
args: | |
description: | |
- Keyword arguments to pass to the `cli` method | |
required: True | |
''' | |
EXAMPLES = ''' | |
- napalm_cli: | |
args: | |
commands: | |
- show version | |
- show snmp chassis | |
''' | |
RETURN = ''' | |
changed: | |
description: ALWAYS RETURNS FALSE | |
returned: always | |
type: bool | |
sample: True | |
results: | |
description: string of command output | |
returned: always | |
type: dict | |
sample: '{ | |
"show snmp chassis": "Chassis: 1234\n", | |
"show version": "Arista vEOS\nHardware version: \nSerial number: \nSystem MAC address: 0800.27c3.5f28\n\nSoftware image version: 4.17.5M\nArchitecture: i386\nInternal build version: 4.17.5M-4414219.4175M\nInternal build ID: d02143c6-e42b-4fc3-99b6-97063bddb6b8\n\nUptime: 1 hour and 21 minutes\nTotal memory: 1893416 kB\nFree memory: 956488 kB\n\n" # noqa | |
}' | |
''' | |
from ansible.module_utils.connection import Connection | |
def main(): | |
module = AnsibleModule( | |
argument_spec=dict( | |
optional_args=dict(required=False, type='dict', default=None), | |
args=dict(required=True, type='dict', default=None), | |
), | |
supports_check_mode=False | |
) | |
args = module.params['args'] | |
optional_args = module.params.get('optional_args', {}) | |
connection = Connection(module._socket_path) | |
cli_response = connection.cli(**args) | |
module.exit_json(changed=False, results=cli_response) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment