Alex Grs
Alex Grs

Reputation: 3301

Fabric : ignore env.hosts when using -H option

When using command -H one can specify hosts on the command line.

Let say by defaut you have set a env.hosts variable with a list of hosts. But sometimes, you need to apply your functions on only one or two of thoses hosts and you need to use -H .

How do you proceed to ignore env.hosts when using this argument ? I don't find any info about it. Is it the good way to achieve this ?

Upvotes: 0

Views: 72

Answers (1)

fernandezcuesta
fernandezcuesta

Reputation: 2448

You can populate env.hosts only when it was not specified as a command line argument like:

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

This way when a CLI argument -H/--hosts is set, env.hosts already contains a value when the fabfile is loaded and you're not overwritting its value.

As stated in documentation, hosts list specified from CLI are the latest in the precedence order, thus may be overriden by others.

Upvotes: 1

Related Questions