0

I know I can assign hosts with fabric by doing this:

env.hosts = ['host1', 'host2']

But can I do this?

myList = ['host1', 'host2']
env.hosts = myList

I am getting a list of 'public_dns_name's using Boto (from Amazon AWS) and then want to run commands on those servers. The server list can be dynamic so I need to be able to assign the hosts environment variable rather than statically. Can anyone suggest a solution?

myHosts = []
for i in myInstances:
    publicDnsAddress = i.public_dns_name
    myHosts.append(i.public_dns_name)
    print ("public dns address: " + publicDnsAddress)

print ("myHosts = " + str(myHosts))        

env.hosts=myHosts
env.user='myUser'
run("/scripts/remote_script.py")

I get this error:

No hosts found. Please specify (single) host string for connection: 

If the host names were bad I would expect at least a connection error rather than a message saying it could find no hosts. Granted I may be calling this thing wrong but then again, that is why I am asking for help.

Bill Rosmus
  • 2,941
  • 7
  • 40
  • 61

1 Answers1

0

When dynamically setting hosts within the code, I've needed to use this with settings pattern:

user = 'root'
hosts = ['server1', 'server2']

for host in hosts:
    with settings(user=user, host_string=host):
        run(whatever_my_command_is)
klenwell
  • 6,978
  • 4
  • 45
  • 84