Slide 12
Slide 12 text
{ "ʺevent"ʺ: "ʺpybcn"ʺ, "ʺauthor"ʺ: "ʺPablo Enfedaque"ʺ, "ʺtwi3er"ʺ: "ʺ@pablitoev56"ʺ}
An example of fabfile.py
#!/usr/bin/env python2.7
#-*- coding: utf-8 -*-
from fabric.api import run, sudo, cd, env, task, lcd, put
from fabric.contrib.files import upload_template
env.use_ssh_config = True
env.abort_on_prompts = True
env.roledefs = {"web": ["host1", "host2"], "backend": ["host3", "host4"]}
@task
def list_cfg_files():
"List and print the files in /etc/my_app"
with cd("/etc/my_app"):
run("ls -lAhtr *.cfg")
run("cat *.cfg")
def this_is_not_a_task():
"This is not a task"
# Do something here
@task
def push_config_files(port=1234):
"Push config files, setting the provided port"
with lcd("conf"), cd("/etc/my_app"):
for filename in "general.cfg", "static.cfg", "logging.cfg":
put(filename, filename)
upload_template("web.cfg", ".", context={"PORT": port}, backup=True)
sudo("service my_app restart")