Discussion:
[Fab-user] Using execute appears to break ssh_config configuration
Matthias Witte
2014-08-19 15:21:04 UTC
Permalink
Hi,

I have a fabfile test.py like this

---------------------------------------------------------------------
from fabric.api import *

env.hosts = ['foo.bar.baz', 'boo.bar.baz']

@task
def simple():
run("uname -a")

@task
@runs_once
def simple_go():
execute(simple)

@task
def simple_gogo():
execute(simple)
---------------------------------------------------------------------

__init__.py contains

---------------------------------------------------------------------
env.ssh_config_path = os.path.expanduser("~/.ssh/config.fab")
env.use_ssh_config = True
---------------------------------------------------------------------

where config.fab looks like this

---------------------------------------------------------------------
Host foo.bar.baz
Hostname 10.1.2.3

Host boo.bar.baz
Hostname 10.1.2.4

Host foo.*
User root

Host *.baz
User ubuntu
---------------------------------------------------------------------

i.e. hosts named foo.* require login as root, everything else as ubuntu.

If I run

fab test.simple

everything works as expected, that is the script logs into foo as root
and into boo as
user ubuntu.

If I try this with the workhorse pattern

fab test.simple_go

or even without the @runs_once decorator

fab test.simple_gogo

it succeeds to log into foo as root, but then tries to log into boo as
well as root.

Is this the intended if somewhat unexpected behaviour of execute or
have I hit on a bug?

paramiko as well as ssh and parallel-ssh work fine with the given
ssh_config so the problem
is unlikely due to incorrect ssh_config parsing. Only using execute
triggers this behaviour.

I am willing to extend my debugging foo, but would like to be sure
this is a real bug and not
me doing something I should not be doing.

Kind regards,

Matthias
--
Matthias Witte
Email: ***@g.zamiam.de
Brandon Whaley
2014-08-19 15:24:31 UTC
Permalink
Hi Matthias,

How are you loading the contents of __init__.py? I don't see any
module imports in your test.py file. I would generally put what you
have there directly in the fabfile itself, right after the fabric.api
import.

On Tue, Aug 19, 2014 at 11:21 AM, Matthias Witte
Post by Matthias Witte
Hi,
I have a fabfile test.py like this
---------------------------------------------------------------------
from fabric.api import *
env.hosts = ['foo.bar.baz', 'boo.bar.baz']
@task
run("uname -a")
@task
@runs_once
execute(simple)
@task
execute(simple)
---------------------------------------------------------------------
__init__.py contains
---------------------------------------------------------------------
env.ssh_config_path = os.path.expanduser("~/.ssh/config.fab")
env.use_ssh_config = True
---------------------------------------------------------------------
where config.fab looks like this
---------------------------------------------------------------------
Host foo.bar.baz
Hostname 10.1.2.3
Host boo.bar.baz
Hostname 10.1.2.4
Host foo.*
User root
Host *.baz
User ubuntu
---------------------------------------------------------------------
i.e. hosts named foo.* require login as root, everything else as ubuntu.
If I run
fab test.simple
everything works as expected, that is the script logs into foo as root
and into boo as
user ubuntu.
If I try this with the workhorse pattern
fab test.simple_go
fab test.simple_gogo
it succeeds to log into foo as root, but then tries to log into boo as
well as root.
Is this the intended if somewhat unexpected behaviour of execute or
have I hit on a bug?
paramiko as well as ssh and parallel-ssh work fine with the given
ssh_config so the problem
is unlikely due to incorrect ssh_config parsing. Only using execute
triggers this behaviour.
I am willing to extend my debugging foo, but would like to be sure
this is a real bug and not
me doing something I should not be doing.
Kind regards,
Matthias
--
Matthias Witte
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Matthias Witte
2014-08-19 15:38:00 UTC
Permalink
Hi Brandon,

I use a fabfile directory, which contains __init__.py and test.py

The complete __init__.py looks like this

-------------------------------------------------------------------------------------------
from fabric.api import *
from fabric.contrib.console import confirm

import os.path

env.no_agent = False

env.ssh_config_path = os.path.expanduser("~/.ssh/config.fab")
env.use_ssh_config = True

import test
-------------------------------------------------------------------------------------------

and the actual test.py is without the env.ssh_config_path and env.use_ssh_config
assignments (which I included in my example).

Kind regards,

Matthias
--
Matthias Witte
Email: ***@g.zamiam.de
Telefon: +49 211 30 43 43
Mobil: +49 175 43 17 826
Brandon Whaley
2014-08-19 15:51:05 UTC
Permalink
Ahh, that clears up the structure for me, thanks.

Can you try passing the list of hosts to the 'hosts' keyword argument
of execute?

On Tue, Aug 19, 2014 at 11:38 AM, Matthias Witte
Post by Matthias Witte
Hi Brandon,
I use a fabfile directory, which contains __init__.py and test.py
The complete __init__.py looks like this
-------------------------------------------------------------------------------------------
from fabric.api import *
from fabric.contrib.console import confirm
import os.path
env.no_agent = False
env.ssh_config_path = os.path.expanduser("~/.ssh/config.fab")
env.use_ssh_config = True
import test
-------------------------------------------------------------------------------------------
and the actual test.py is without the env.ssh_config_path and env.use_ssh_config
assignments (which I included in my example).
Kind regards,
Matthias
--
Matthias Witte
Telefon: +49 211 30 43 43
Mobil: +49 175 43 17 826
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Matthias Witte
2014-08-19 16:00:18 UTC
Permalink
Hi Brandom,

that ends up the same way both in simple_go and simple_gogo if I change
the execute call to

execute(simple, hosts=env.hosts)

trying to log into boo as root when ubuntu is configured in ssh_config.

Kind regards,

Matthias
--
Matthias Witte
Email: ***@g.zamiam.de
Matthias Witte
2014-08-19 16:24:59 UTC
Permalink
Hi,

I was just running a debugging session with ipdb and when I start
single stepping the
second node's turn in the for loop in

fabric/tasks.py(376)execute() down to
fabric/network.py(324)to_dict()

normalize('boo.bar.baz') will return the correct address for the node
as configured by the HostName assignment but the user returned is root
and not ubuntu.

Kind regards,

Matthias
--
Matthias Witte
Email: ***@g.zamiam.de
Loading...