How to install and use python's deployment tool fabric. An OS that can use yum such as CentOS is a prerequisite.
Install the required packages.
yum install gcc python-devel python-setuptools
easy_install pip
pip install fabric
Confirm that it has been installed.
fab -V
Execute a command to the remote server to get system information. It is assumed that you can connect by specifying the host name with ssh. (Set ./ssh/config file, etc.)
Create a fabfile.
from fabric.api import run, env
env.use_ssh_config = True
def uname():
run("uname")
Execute the fab command. (Specify the host name in hostname)
fab -H hostname uname
#Command execution on remote server
run("command")
#Command execution on local server
local("command")
#Send file to remote server
put("{Source file path}", "{Destination file path}")
#Receive files from remote server
get("{Source file path}", "{Destination file path}")
Specify the module first when executing each command.
from fabric.api import run, env, local, put, get
Recommended Posts