Harman
Harman

Reputation: 727

run fabric file renamed other than fabfile.py and password-less ssh

I had a working code, which now I am unable to run due to some issues.

I am facing the following issues:

  1. I am prompted for password, as I run the file using python /path/to/file.py

  2. Even if I use fab -l, this file is invoked and I am again prompted for password.

Just to let you know, I have a lot of .py (including fabfile.py) files in the directory which are using fabric and other libraries.

Here is a snippet of my code:

from fabric.api import *

env.key_filename = /path/to/my/pem/file

def mem_usage():
   '''Check free mem'''
   run('free -m')

execute(mem_usage, host="user@IP_or_hostname")

Please help with my understanding:

  1. How can I ssh using pem file without passing the path through command-line arguments

  2. How can I run the code (file named foo.py)

Any pointers would be highly appreciated.

Upvotes: 2

Views: 872

Answers (1)

Harman
Harman

Reputation: 727

So, I found the solution to my question.

  1. It was just a stupid thing not to check my pem file, which was secured with a passphrase.

  2. The python file can be named anything, as far as it has an execute method - and it is executed just like a normal python program. Let's say foo.py, then it will be executed using python foo.py

Upvotes: 2

Related Questions