Discussion:
[Fab-user] Using reboot in a fabfile
Daniel Lumb
2018-08-08 11:38:48 UTC
Permalink
Hi all,


New to Fabric and this is a very basic question but I'm finding it crazily hard to find the right documentation/usage examples...


I'm trying to create a series of tasks in fabfile.py, one of these tasks is solely intended to reboot the target servers. I can't seem to define this in a way that works, this is what I have:


@task
def reboot():
with hide ("everything"), show ("stderr"):
reboot



This runs OK using the fab binary on the CLI but it doesn't seem to actually do anything on the target servers. I've tried a fair few other things and haven't had any success.


Apologies this is so simple, a link to any relevant documentation is fine.



Thanks,

Dan
Jeff Forcier
2018-08-08 16:16:00 UTC
Permalink
Hi Dan,

Can you post your entire fabfile (with anything sensitive removed, and
including import statements) on, say, gist.github.com or dpaste.com? The
example in the email itself has a handful of issues but seeing the whole
thing will make some of them clearer :)

I can definitely say that if your post below is literal, your first issue
is you probably aren't actually calling `reboot` because there's no
parentheses after it! (`reboot` vs `reboot()`) - but depending on your
imports, once you fix that you'll probably have a few more problems
besides...

Here's what you are _probably_ going for, by the way:

```
from fabric.api import task, reboot as builtin_reboot

@task
def reboot():
with hide("everything"), show("stderr"):
builtin_reboot()
```

(With option to name your task something besides `reboot`, and then not
doing the `import x as y` form when importing the builtin.)

Best,
Jeff

On Wed, Aug 8, 2018 at 4:38 AM, Daniel Lumb <***@outlook.com> wrote:

> Hi all,
>
>
> New to Fabric and this is a very basic question but I'm finding it crazily
> hard to find the right documentation/usage examples...
>
>
> I'm trying to create a series of tasks in fabfile.py, one of these tasks
> is solely intended to reboot the target servers. I can't seem to define
> this in a way that works, this is what I have:
>
>
> @task
> def reboot():
> with hide ("everything"), show ("stderr"):
> reboot
>
>
> This runs OK using the fab binary on the CLI but it doesn't seem to
> actually do anything on the target servers. I've tried a fair few other
> things and haven't had any success.
>
>
> Apologies this is so simple, a link to any relevant documentation is fine.
>
>
>
> Thanks,
>
> Dan
>
> _______________________________________________
> Fab-user mailing list
> Fab-***@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/fab-user
>
>


--
Jeff Forcier
Unix sysadmin; Python engineer
http://bitprophet.org
Jacob McCoy Wade
2018-08-08 15:27:53 UTC
Permalink
Well, unless you are connecting to the server as root, you are probably going to need to use sudo?
@task
def reboot():
With hide(“everything”), show (“stderr”):
sudo(‘reboot’)

???

> On Aug 8, 2018, at 4:38 AM, Daniel Lumb <***@outlook.com> wrote:
>
> Hi all,
>
> New to Fabric and this is a very basic question but I'm finding it crazily hard to find the right documentation/usage examples...
>
> I'm trying to create a series of tasks in fabfile.py, one of these tasks is solely intended to reboot the target servers. I can't seem to define this in a way that works, this is what I have:
>
> @task
> def reboot():
> with hide ("everything"), show ("stderr"):
> reboot
>
>
> This runs OK using the fab binary on the CLI but it doesn't seem to actually do anything on the target servers. I've tried a fair few other things and haven't had any success.
>
> Apologies this is so simple, a link to any relevant documentation is fine.
>
>
> Thanks,
> Dan
> _______________________________________________
> Fab-user mailing list
> Fab-***@nongnu.org <mailto:Fab-***@nongnu.org>
> https://lists.nongnu.org/mailman/listinfo/fab-user <https://lists.nongnu.org/mailman/listinfo/fab-user>
Daniel Lumb
2018-08-09 10:56:59 UTC
Permalink
Sure, here's a the fabfile - it's very basic and it's just me testing out some automated upgrades in Ubuntu. Pointers and advice are welcome. Basically I have another python script that acts as a wrapper for the fabfile, selecting server targets and then invoking 'fab' from the cli to run the jobs. This probably isn't the best way to do it but...


http://dpaste.com/0H7GNX8 . -- some of the indenting got messed up but you get the idea!


As you can see, I've resorted to using "at" to schedule the reboots...


Another aspect I'm confused with is error handling and output manipulation. I'd love to be able to grab output from each "job", which seems like it may be difficult, especially during parallel execution tasks.


Thanks,

Dan

________________________________
From: Fab-user <fab-user-bounces+daniel.lumb=***@nongnu.org> on behalf of Jacob McCoy Wade <***@mccoywade.org>
Sent: 08 August 2018 16:27:53
To: fab-***@nongnu.org
Subject: Re: [Fab-user] Using reboot in a fabfile

Well, unless you are connecting to the server as root, you are probably going to need to use sudo?
@task
def reboot():
With hide(“everything”), show (“stderr”):
sudo(‘reboot’)

???

On Aug 8, 2018, at 4:38 AM, Daniel Lumb <***@outlook.com<mailto:***@outlook.com>> wrote:

Hi all,

New to Fabric and this is a very basic question but I'm finding it crazily hard to find the right documentation/usage examples...

I'm trying to create a series of tasks in fabfile.py, one of these tasks is solely intended to reboot the target servers. I can't seem to define this in a way that works, this is what I have:


@task
def reboot():
with hide ("everything"), show ("stderr"):
reboot


This runs OK using the fab binary on the CLI but it doesn't seem to actually do anything on the target servers. I've tried a fair few other things and haven't had any success.

Apologies this is so simple, a link to any relevant documentation is fine.


Thanks,
Dan
Loading...