I am learning how to create ansible modules in python, I want to connect to remote devices, I am looking at ansible source code to see how they connect, but I still cant understand how???
I took this simple module file from ansible to check how they connect to the remote device and do all the stuff that the module does
https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/ping.py
I don't see any socket or libraries for ssh in this file, so how does it happed?
does ansible first connect to the remote host and then activate the module on the remote host?
is that why it requires python on remote devices?
I cant really understand it
As far as i know, Ansible use ssh to connect.
You can perform a research whith 'repo:ansible/ansible filename:ssh' in
github research here
You can examin this code.
Ansible also use the lib paramiko to connect with ssh.
as we can see here
Related
I wonder if there is any way to coding python with remote server data and run the python script on remote server with pycharm only installed on my local machine?
The remote server can be access by two ip address (ssh and ftp each), id and password.
But when I try to use pycharm professional project interpreter, there always an error like this (the ip address I used is for ssh):
I know the easiest way is install jupyter notebbok on my remote server, but I don't have permission to do that.
I have a common VM and remote VM. we have network devices, only remote VM has access to network devices.
Python script will do configurations in network devices.
I must trigger a python script from common VM.
To implement this Currently I have two options in my mind.
Configure password less between common vm to remote vm. Trigger a script from common vm which copies script to remote vm then start execution.
directly ssh using paramiko to remote and again ssh using paramiko to network devices (This option is not tried, I am going to try now)
Which is the better method or any other suggestions will welcome.
Thanks
Here is what I am trying to do. I have a Windows VM and another Linux VM which is used as server. I have Spyder installed on my Windows VM and would like to run my Python code in Spyder on remote Linux server.
I did try using option in Spyder called "Connect to remote kernel" but it did not work and I am getting error "Could not open ssh tunnel ; Paramiko not available". I was using username#servername:22 for making ssh connection. Needless to say, I am able to ssh the machine using putty but not using Spyder. Any ideas how should I fix this?
I found another way to make a connection to an external server, here is the link explaining step by step.
Basically, you have to connect your client PC to the server through a PuTTY SSH tunnel, it will allow to redirect the client ports to the correct ipython kernel server ports.
i am new to python scripting can someone please assist belo
1.read server, username and password
2.connect unix server
3.change directory and execute command
need some examples for above.
You can use the excellent paramiko package for this. It is an SSH (and SFTP) client library, which will let you easily connect to a Unix server running an ssh service, run commands, transfer files, etc.
You can also use fabric. Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
I use ssh deployment on servers via ssh tunnels,
and each of its has specific options and port forwarding placed in ~/.ssh/config.
PyCharm uses by default its own ssh client when using SFTP deploy.
So, it doesn't work with these deployment servers.
How I could force PyCharm to use my default system ssh client or force to use options from ~/.ssh/config file.
Thanks.
PS: PyCharm version is 3.0.1
Provided PyCharm can be made to use port different than 22 (don't know that), you actually have two workarounds:
Simple workaround
Use port forwarding on localhost:
http://www.debian-administration.org/article/449/SSH_dynamic_port_forwarding_with_SOCKS
..and either use -F specific_config for each tunnel, or use -o to specify relevant options (that you normally have in ~/.ssh/config on ssh commandline) directly. Of course, you have to tell PyCharm to connect to localhost:forwarded_port.
Fancy/sophisticated workaround
Use dynamic port forwarding + tsocks, again described in:
http://www.debian-administration.org/article/449/SSH_dynamic_port_forwarding_with_SOCKS