On a related note, if you use Puppet and want to grab a list of hosts for Fabric (env.hosts) via the Puppet API check out
https://github.com/snobear/fabpup .
It’s a simple lib I started working on. I’d be happy to put more effort into it if there is an interest out there. Let me know.
In your fabfile, for example:
import fabpup
# settings - see fabpup.py for available settings
fabpup['host'] = 'puppet.example.com' # your puppetmaster host
# create a dict with facts to match on
myfacts = {'facts.operatingsystem':'CentOS',
'facts.lsbdistrelease':'6.2'
}
# return a list of hosts for Fabric
env.hosts = get_hosts_by_facts(myfacts)
From: fab-user-bounces+address@hidden [mailto:fab-user-bounces+address@hidden
On Behalf Of William Cannon
Sent: Thursday, July 12, 2012 12:06 PM
To: address@hidden
Subject: Re: [Fab-user] Fab-user Digest, Vol 54, Issue 6
Ryan,
I have found it is very convenient to use fabric as a library (rather than using "fab myfunction" ) for this type of purpose.
For instance, you can alter the env.host_string at runtime with any target host as desired.
-William
On Thu, Jul 12, 2012 at 11:00 AM, <address@hidden> wrote:
Send Fab-user mailing list submissions to
address@hidden
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.nongnu.org/mailman/listinfo/fab-user
or, via email, send a message with subject or body 'help' to
address@hidden
You can reach the person managing the list at
address@hidden
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Fab-user digest..."
Today's Topics:
1. Execute the same tasks in local() and run() (Jorge Vargas)
2. Dynamic hosts not supported by -H? (Ryan Bales)
3. Re: Execute the same tasks in local() and run() (Todd DeLuca)
----------------------------------------------------------------------
Message: 1
Date: Thu, 12 Jul 2012 04:05:07 -0400
From: Jorge Vargas <address@hidden>
To: fab-user <address@hidden>
Subject: [Fab-user] Execute the same tasks in local() and run()
Message-ID:
<address@hidden>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
We are using fabric for development as well as deployment and I'm wondering
how people are doing command like this.
@task
def load_fixtures():
"""Load initial data."""
run("venv/bin/python data/fixtures.py")
This code should work for both the developer machine (ie: run local) and
the deployment machine (ie: use run)
So far what I have done is something like
@task
def install_db(command=local):
"""@onetime install of the database"""
with prefix("source venv/bin/activate"):
command("python manage.py syncdb --migrate")
However that's a bit of a problem as I can't call that command from fab
just from other fabric scripts.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nongnu.org/archive/html/fab-user/attachments/20120712/941560fa/attachment.html>
------------------------------
Message: 2
Date: Thu, 12 Jul 2012 08:26:38 -0500
From: Ryan Bales <address@hidden>
To: fab-user <address@hidden>
Subject: [Fab-user] Dynamic hosts not supported by -H?
Message-ID:
<CAC5M4J2zOfZMUdZ2QkcR6ifkbPTPiGiybkNr++address@hidden>
Content-Type: text/plain; charset="iso-8859-1"
Hello all,
I'm trying to build a web app around a few fabric scripts, and I need to
supply a dynamic list of hosts to the scripts. I saw the -H switch, but it
apparently only works when env.hosts is defined in the fabric script. I
also looked at command-line kwargs for methods, but the methods won't even
be executed without env.hosts being defined. Can someone point me in the
right direction?
Thanks,
--
Ryan Bales
http://thinkt4nk.com/
http://twitter.com/#!/thinkt4nk
https://github.com/thinkt4nk
--
Ryan Bales
http://thinkt4nk.com/
http://twitter.com/#!/thinkt4nk
https://github.com/thinkt4nk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nongnu.org/archive/html/fab-user/attachments/20120712/7a596f6e/attachment.html>
------------------------------
Message: 3
Date: Thu, 12 Jul 2012 09:32:04 -0400
From: Todd DeLuca <address@hidden>
To: Jorge Vargas <address@hidden>
Cc: fab-user <address@hidden>
Subject: Re: [Fab-user] Execute the same tasks in local() and run()
Message-ID:
<address@hidden>
Content-Type: text/plain; charset="iso-8859-1"
The way I deploy to localhost now is to run ssh on my local machine. That
way I can access my local machine "remotely" in fabric scripts. On my mac
laptop, here is how I enabled remote logins via ssh. Go to System
Preferences, choose Sharing. Select Remote login. That's it. This
approach seems to fit into the fabric model well.
I used to deploy locally by following the advice at
http://stackoverflow.com/questions/6725244/running-fabric-script-locally.
Basically, I would assign env.run = run or env.run = local, depending on
where I was deploying, perhaps in a task something like (warning: untested
code):
```
env.run = run
@task
def localhost():
env.run = local
@task
def do_something():
env.run('path/to/myscript.py')
```
Then I would do invoke it like:
```
fab local do_something
```
This got smellier when I started rsyncing, since I had to write a
local version and remote version of rsync. Then when I started
using `fabric.api.get`, I realized that I would have to write a API
compatible version of `get` and `put` if I wanted to continue down this
path. That pushed me to find the better way described above.
Hope that helps.
-Todd
On Thu, Jul 12, 2012 at 4:05 AM, Jorge Vargas <address@hidden>wrote:
> Hello,
>
> We are using fabric for development as well as deployment and I'm
> wondering how people are doing command like this.
>
> @task
> def load_fixtures():
> """Load initial data."""
> run("venv/bin/python data/fixtures.py")
>
> This code should work for both the developer machine (ie: run local) and
> the deployment machine (ie: use run)
>
> So far what I have done is something like
>
> @task
> def install_db(command=local):
> """@onetime install of the database"""
> with prefix("source venv/bin/activate"):
> command("python manage.py syncdb --migrate")
>
> However that's a bit of a problem as I can't call that command from fab
> just from other fabric scripts.
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user
>
>
--
Todd DeLuca
http://todddeluca.com
http://wall.hms.harvard.edu/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nongnu.org/archive/html/fab-user/attachments/20120712/c4a9c1af/attachment.html>
------------------------------
_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user
End of Fab-user Digest, Vol 54, Issue 6
***************************************
Information in this e-mail may be confidential. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication
is strictly prohibited. If you have received this e-mail in error, please notify the sender of the error.
|