4

In my code I wish to have a list of hosts and send a different parameter to each host.

Currently I find the index in the array and use that to determine the input

index = env.hosts.index(env.host_name)

Hosts and host_name is no longer used in fabric 3 with it saying.

The primary API is now properly OOP: instantiate Connection objects and call their methods. These objects encapsulate all connection state (user, host, gateway, etc) and have their own SSH client instances.
RonanMacF
  • 309
  • 2
  • 9

1 Answers1

1

In Fabric 2, you connect to a host by instantiating a Connection object. You can access its host by invoking the host attribute:

conn = Connection('192.168.11.12')
print(conn.host)

Should you need to connect to multiple servers, you will need to instantiate a SerialGroup composed of multiple connections

g = SerialGroup('192.168.11.12', '192.168.11.13')
for conn in g:
    print(conn.host)

You can have look at the (updated!) docs here, and the (updated!) git repo here

Ismaïl Mourtada
  • 452
  • 5
  • 11
  • Simply by passing the connection object as an argument of your task, and looping through all the connections in the Group. Example here : https://docs.fabfile.org/en/2.4/getting-started.html#bringing-it-all-together – Ismaïl Mourtada Oct 03 '18 at 10:03
  • 4
    I use it command line `fab task`, so I don't pass connection object myself. – Suor Oct 04 '18 at 05:05