Python newbie here. Lets say I have this:
def test_servers():
env.user = getpass.getuser()
env.hosts = []
And I want to do something like this:
def test_servers():
env.user = getpass.getuser()
system = raw_input("Enter FQDN to show (seperated by commas for multiple entries)> ")
env.hosts = system.split(',')
??How do I make it populate as:
env.hosts = ['firsthostinput', 'secondhostinput']
I'm still learning python and I'm not sure if system split can be combined with something else to do the format of what I want it to populate as. Any help would be greatly appreciated.
EDIT:
This is for my fab file. Just doing the system.split doesn't work. And because of a specific parameter "audit" I can't just pass hosts on the command line. They must be in input_servers().
So, this is what I have in my fabfile.py:
def input_servers():
env.user = getpass.getuser()
system = raw_input("Enter FQDN. User Commas to seperate multiple servers > "
env.hosts = system.split(',')
This is what happens if I try to run it:
[me@mothership fab_files]$ fab input_servers audit
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/fabric/main.py", line 654, in main
docstring, callables, default = load_fabfile(fabfile)
File "/usr/lib/python2.6/site-packages/fabric/main.py", line 165, in load_fabfile
imported = importer(os.path.splitext(fabfile)[0])
File "/home/me/my-repo/stuff/fab_files/fabfile.py", line 17
env.hosts = system.split(',')
^
SyntaxError: invalid syntax