Reputation: 1
The use case is as follows.
---
- name: Playbook to run custom module
hosts: "10.28.10.1"
connection: network_cli
gather_facts: false
vars:
ansible_network_os: nokia.sros.classic
tasks:
- name: Run Show Version
cli_command:
command: "show version"
register: result
- name: Execute Custom Module
cli_command_for_secondary_device:
command: "show version"
secondary_device: "10.28.10.2"
register: result
Here devices are from nokia, I wanted to execute a command on secondary device "10.28.10.2" from a server using ansible-playbook but we can't do direct SSH to this device hence we need to first connect to primary device "10.28.10.1" then again do SSH to secondary device and execute the command.
To achieve this I may have to write a custom module like below which accepts primary ip, secondary ip and command.
- name: Execute Custom Module
cli_command_for_secondary_device:
command: "show version"
primary_device: "10.28.10.1"
secondary_device: "10.28.10.2"
register: result
Internally custom module will do SSH to primary first "10.28.10.1" then SSH to 10.28.10.2 and executes the command without using Ansible created SSH connection. So this process will increase our run time of playbook.
Hence I wanted to use existing ansible created SSH connection (internal Connection obj in Python) in my custom module so that it will do direct SSH to secondary ip 10.28.10.2 without creating explicit connection again. This improves the performance too.
Upvotes: 0
Views: 284