Hi, https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html
Refer this link. It will show how to create custom modules. On Sun, 14 Jun, 2020, 2:39 am Ashwajit Bhoutkar, <[email protected]> wrote: > Hi, > > Thank you for your reply. I'm very much new to ansible and hav been > running only raw commands which I've learned from online tutorials. I've > made a small modular program in python which uses the paramiko library. > Below is the structure of the code which I've written in python to change > the ip address of some interfaces (the code has other modules as well which > write the results of these executions on excel). In the program, i've > created a class to create ssh connection with a server, and then use the > connection object in next class to connect to devices and then send > commands to my devices and get the relevant outputs. > I just wanted to know how this functionality can be achieved with the help > of ansible? It would be a great help for me if someone could provide me the > solution. Thank you in advance for the support. > > import paramiko > > class connection(): > > def __init__(self, address, username, password): > #connection module > > def openShell(self): > #invoke shell module > > def sendShell(self, command, show="show"): > #send shell module > > def getdata(self): > #get shell data module > > def closeConnection(self): > #close connection > > class connectToDevices(): > > def __init__(self, var1, var2): > #connect to jumphost > > def assign_ip(int, address): > #get existing ip > #comare with provided ip > #assign IP if different else do nothing > > def get_ip(int, address): > #capture existing ip > > Thank You, > > Kind Regards, > Ashwajit > > On Thu, Jun 11, 2020 at 10:15 PM Sydo Luciani <[email protected]> > wrote: > >> Yes, you can use command module to run commands on targets that has >> python interpreter, >> or use raw module if python interpreter is not available on target >> mashine. >> check out example section: >> >> https://docs.ansible.com/ansible/latest/modules/list_of_commands_modules.html >> >> https://docs.ansible.com/ansible/latest/modules/raw_module.html#raw-module >> >> You don't need to worry about the type of ssh client. >> Ansible is going to take care of it, as long as you have proper >> ansible.cfg configuration file in place. >> >> https://docs.ansible.com/ansible/latest/user_guide/connection_details.html >> >> >> >> >> >> On Thu, 11 Jun 2020 at 10:25, Ashwajit Bhoutkar < >> [email protected]> wrote: >> >>> Hello, >>> >>> >>> >>> I've question related to a scenario which I can accomplish using Python >>> but would like to achieve the same using Ansible. >>> >>> >>> >>> In the scenario, I first execute "show run int" command to see if it has >>> IP address allocated, if ip is not allocated then a new IP address is >>> allocated to the interface else no action is taken. Finally I again do the >>> “show ip int” command and verify whether the IP is allocated. For the >>> scenario, I’ve used Paramiko library, I’ve made a connect class which gives >>> me the connection object, and I’ve defined small function for various >>> commands and its outputs, these functions used the connection object to run >>> the command on the devices. Is it possible to achieve the same using >>> Ansible? >>> >>> >>> >>> Thank You >>> >>> >>> >>> Kind Regards, >>> >>> Ashwajit >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ansible Project" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/ansible-project/0526ffef-6329-4d5b-89a2-868940cff438o%40googlegroups.com >>> <https://groups.google.com/d/msgid/ansible-project/0526ffef-6329-4d5b-89a2-868940cff438o%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ansible Project" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/CAJspodhhi%2BT%2BE9ScvfAiNrPy838xh9kwhGv_Td2R1Ct8D6fDRg%40mail.gmail.com >> <https://groups.google.com/d/msgid/ansible-project/CAJspodhhi%2BT%2BE9ScvfAiNrPy838xh9kwhGv_Td2R1Ct8D6fDRg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/CAE9NbXwOWm%2B1viuSfxArFobVMbgvE9nKxehDvbszsj3W%3Djk-Pg%40mail.gmail.com > <https://groups.google.com/d/msgid/ansible-project/CAE9NbXwOWm%2B1viuSfxArFobVMbgvE9nKxehDvbszsj3W%3Djk-Pg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKuA%2BXdfF_3B9DYs%3Dsxmt%2BQfRFsUr0W0ornyZQx-2DjAf0ru%2Bw%40mail.gmail.com.
