Warz
Warz

Reputation: 7746

How to read fabric environment variables set with cli

How can i read environment variables that I have set using the cli tool. For example, I have an empty fabfile.py in my cwd and when i run fab --set password=foo,host_string=host1 and then run a python console to see if those fab environment variables were set -

from fabric.api import env
print env.host_string 

I get nothing back ?

Upvotes: 2

Views: 1399

Answers (2)

Morgan
Morgan

Reputation: 4131

You can't set the host_string like that. That variable is set internally, after doing some string manipulation to the passed raw host. If you want to specify a specific host to use, call your fab task just use the flag for this and call your talk like:

$ fab -H host1 --set password=foo sometask

If you wanted to pass a host to a function you can also do this, but use a different variable name.

Upvotes: 0

alecxe
alecxe

Reputation: 473863

According to the documentation, multiple env variables has to be comma-separated:

fab --set password=foo,host_string=host1

Demo:

$ cat fabfile.py
from fabric.api import env

print env['hello']
print env['world']
$ fab test --set hello=1,world=2
1
2

Upvotes: 3

Related Questions