AWS Simple Icons v2.1 released
Old version is still available, too.
fabfile.py
from fabric.api import task,local
@task
def whoami():
local("who am i")
Execute!
$ fab whoami
[localhost] local: who am i
someda ttys000 Jun 11 23:30
Done.
Application deployment/Continuous Delivery
Are you familier with Python?
Amazon Linux AMI release 2013.03 premised
Setup pyenv beforehand
$ cd
$ git clone git://github.com/yyuu/pyenv.git .pyenv
$ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
reload shell and install Python
$ pyenv install 2.7.5
$ pyenv rehash
$ pyenv global 2.7.5
$ pyenv versions
Build tools
$ sudo yum install gcc make patch -y
$ sudo yum install subversion git -y
Prerequisites
$ sudo yum install readline-devel-y
$ sudo yum install sqlite-devel -y
$ sudo yum install zlib-devel bzip2-devel -y
$ sudo yum install openssl-devel -y
$ pip install fabric
$ pyenv rehash
$ which fab
to upgrade
$ pip install --upgrade fabric
$ fab -V
Fabric 1.6.1
Paramiko 1.10.1
Create fabfile.py and add tasks
from fabric.api import task,local,run
@task
def localtime():
local("date")
@task
def remotetime():
run("date")
def private():
print("private method")
use new style task to distinguish tasks and other private functions clearly
List your tasks on fabfile.py
$ fab -l
Available commands:
localtime
remotetime
Execute specified task by passing its name as argument to fab
$ fab localtime
[localhost] local: date
2013年 6月12日 水曜日 03時50分53秒 JST
Done.
only 3 methods to run command
run("uname -a")
sudo("/etc/init.d/httpd graceful")
local("ls -la")
command line agument
# globally
$ fab remotetime -H ec2-user@ec2-XX.ap-northeast-1.compute.amazonaws.com
# per task
$ fab remotetime:hosts="ec2-user@ec2-XX.ap-northeast-1.compute.amazonaws.com"
global definition on fabfile
from fabric.api import env
env.hosts = ['ec2-user@ec2-XX.ap-northeast-1.compute.amazonaws.com']
per task definition on fabfile
from fabric.api import task,run,hosts
@hosts('ec2-user@ec2-XX.ap-northeast-1.compute.amazonaws.com')
@task
def remotetime():
run("date")
prepare ssh config
# saved as ssh.config
Host web01
User ec2-user
HostName ec2-XX.ap-northeast-1.compute.amazonaws.com
Available options are limited compared to actual ssh, see details
enable ssh config loading
from fabric.api import task,local,run,hosts,env
env.use_ssh_config = True
env.ssh_config_path = 'ssh.config'
execute with shortened name
$ fab remotetime -H web01
integrate with AWS API like
para para manga
Powered by Cacoo art