#Fabric
Lord Junior 6th Gregory Eric Sanderson Turcot Temlett MacDonnell of Glengary Forbes of Linden
layout: false
- http://docs.fabfile.org
- SSH lib in python
- Automation of sysadmin tasks
- Similar goals
- Different approach
- Chef/Puppet are full-fledged frameworks
- Fabric feels more like a micro-framework
- I <3 python
fabfile.py
def hello():
print("Hello world!")
running the code:
$ fab hello
Hello world!
Done.
fabfile.py
def hello():
print("Hello world!")
def world():
print("World, Hello!")
running the code:
$ fab hello
Hello world!
Done.
$ fab world
World, hello!
Done.
fabfile.py
from fabric.api import run
def system_type():
run('unname -s')
running the code:
$ fab -H localhost system_type
[localhost] Executing task 'system_type'
[localhost] run: uname -s
[localhost] Login password for 'gregory':
[localhost] out: Linux
[localhost] out:
Done.
Disconnecting from localhost... done.
fabfile.py
from fabric.api import *
DEFAULT_PATH = '/home/gregory/opencode'
DEPLOY_BRANCH = 'deploy'
def deploy(path=DEFAULT_PATH):
add(path)
commit(path)
push(path)
def add(path=DEFAULT_PATH):
with cd(path):
local('git add -i')
def commit(path=DEFAULT_PATH):
with cd(path):
local('git commit -v')
def push(path=DEFAULT_PATH):
with cd(path):
local('git push origin master:%s' % DEPLOY_BRANCH)
running the code:
[localhost] local: git add -i
[localhost] local: git commit -v
[master 001e95a] add hello world
1 file changed, 5 insertions(+)
create mode 100644 hello/fabfile.py
[localhost] local: git push origin master:deploy
Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 394 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To [email protected]:gelendir/opencode-fabric.git
3cc8181..001e95a master -> deploy
Done.
fabfile.py
from fabric.api import run, settings, cd
DEPLOY_PATH = '/tmp/opencode-fabric'
def deploy():
check_deployment()
update()
def check_deployment():
with settings(warn_only=True):
command = run("test -d %s" % DEPLOY_PATH)
if command.failed:
run("git clone git://github.com/gelendir/opencode-fabric %s" % DEPLOY_PATH)
def update():
with cd(DEPLOY_PATH):
run("git pull")
running the code:
$ fab -H localhost deploy
[localhost] Executing task 'deploy'
[localhost] run: test -d /tmp/opencode-fabric
[localhost] Login password for 'gregory':
Warning: run() received nonzero return code 1 while executing 'test -d /tmp/opencode-fabric'!
[localhost] run: git clone git://github.com/gelendir/opencode-fabric /tmp/opencode-fabric
[localhost] out: Cloning into '/tmp/opencode-fabric'...
[localhost] out: remote: Counting objects: 10, done.
[localhost] out: remote: Compressing objects: 100% (6/6), done.
[localhost] out: remote: Total 10 (delta 0), reused 10 (delta 0)
[localhost] out: Receiving objects: 100% (10/10), done.
[localhost] out:
[localhost] run: git pull
[localhost] out: Already up-to-date.
[localhost] out:
Done.
Disconnecting from localhost... done.
- console.confirm
- with sudo()
- parallel execution
- roles
- hosts
- LFS build scripts : https://github.com/gelendir/lfs-build
- XiVO prepare-rc-server : https://gitorious.org/xivo/xivo-tools/
- XiVO prepare-rc-client : https://gitorious.org/xivo/xivo-tools/
- github : gelendir
- twitter : @gelendir
- email : [email protected]