简体   繁体   中英

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 ?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM