I'm clearly just learning. 

Digging into the source, I see that sudo prompts because host_string is not 
set. But that's just one host, which leads me to the fundamental problem: 
fabric is calling my command per host (or once, it seems, if no hosts are 
defined). 

So the only right thing to do is modify hosts outside of the command. It's 
fundamental to the command execution model. 

Bottom line: my mental expectation for command execution is different than 
reality. My naive expectation was that lower-level utilities like sudo, etc. 
would run across all hosts, while my own top-level commands will select hosts. 
Clearly not a good expectation.

That's all for now... having fun learning this stuff.

-Dave

On Mar 9, 2011, at 5:50 PM, Dave Peck wrote:

> 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
[email protected]
http://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to