I want to dynamically populate env.hosts based on a parameter passed into a 
command.

I can see that the settings() context manager is setting env.hosts correctly, 
but the sudo() command inside the block doesn't pick up on it:

        from fabric.context_managers import settings

        env.hosts = [] # These will be selected dynamically

        def mycommand(cloudformation_stack_name):
                
with(settings(hosts=_host_list_from_cfn_stack_name(cloudformation_stack_name)):
                        # I can see that env.hosts is set correctly here.
                        # But: the following sudo() call doesn't seem to know 
it!
                        sudo('echo hello')

My read of the documentation for settings() is that this should work. There's 
nothing in the documentation that says "dynamically modify settings -- unless 
they're settings that you can't dynamically modify." 

That said, I know there are issues modifying env.hosts within a task and I 
assume this may be a permutation. 

What in the fabric codebase leads to this fundamental (and frustrating) 
limitation? Outside of having a separate task dynamically pick hosts, what's a 
good workaround?

Thanks,
Dave



_______________________________________________
Fab-user mailing list
Fab-user@nongnu.org
http://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to