espenak / awsfabrictasks

Other
84 stars 26 forks source link

@ec2instance: login issue #17

Open curiousleo opened 10 years ago

curiousleo commented 10 years ago

When I decorate a task with @ec2instance, it prompts me for a password for the current local user of my local host (instead of using the awsfab-ssh-user user and the default SSH key). I conducted a little test to compare the behaviour of a task decorated with @ec2instance(tags=...) started without --ec2tags and a similar task, not decorated with @ec2instance, but started with --ec2tags=...:

# fabfile.py
from fabric.api import task, run
from awsfabrictasks.decorators import ec2instance

@task
@ec2instance(tags={'Environment':'benchmark'})
def whoami_decorated():
    run('whoami')

@task
def whoami_not_decorated():
    run('whoami')

I would expect awsfab whoami_decorated and awsfab --ec2tags=Environment=benchmark whoami_not_decorated to produce the same results. Alas, awsfab whoami_decorated fails:

leo@localhost $ awsfab whoami_decorated                            
[ec2-IP1.us-west-2.compute.amazonaws.com] Executing task 'whoami_decorated'
[ec2-IP1.us-west-2.compute.amazonaws.com] run: whoami
[ec2-IP1.us-west-2.compute.amazonaws.com] Login password for 'leo': ^C

but awsfab --ec2tags=Environment=benchmark whoami_not_decorated succeeds:

leo@localhost $ awsfab --ec2tags=Environment=benchmark whoami_not_decorated
[root@ec2-IP1.us-west-2.compute.amazonaws.com] Executing task 'whoami_not_decorated'
[root@ec2-IP1.us-west-2.compute.amazonaws.com] run: whoami
[root@ec2-IP1.us-west-2.compute.amazonaws.com] out: root

[root@ec2-IP2.us-west-2.compute.amazonaws.com] Executing task 'whoami_not_decorated'
[root@ec2-IP2.us-west-2.compute.amazonaws.com] run: whoami
[root@ec2-IP2.us-west-2.compute.amazonaws.com] out: root

[root@ec2-IP3.us-west-2.compute.amazonaws.com] Executing task 'whoami_not_decorated'
[root@ec2-IP3.us-west-2.compute.amazonaws.com] run: whoami
[root@ec2-IP3.us-west-2.compute.amazonaws.com] out: root

Done.
Disconnecting from root@ec2-IP3.us-west-2.compute.amazonaws.com... done.
Disconnecting from root@ec2-IP2.us-west-2.compute.amazonaws.com... done.
Disconnecting from root@ec2-IP1.us-west-2.compute.amazonaws.com... done.

Now I'm wondering

  1. Why doesn't whoami_decorated use my SSH key and the awsfab-ssh-user (set to root)?
  2. Why do the two calls give different results?

[This is about @ec2instance just like issue #15, but it is concerned with how it works, not when it is executed, so I decided to open a new issue for it.]