[root@node110 fabric]# cat simple3.py
#!/usr/bin/env python
from fabric.api import *
from fabric.context_managers import *
from fabric.contrib.console import confirm
env.user='root'
#env.gateway='192.168.1.23'
env.gateway='192.168.2.120'
#env.hosts=['192.168.1.21','192.168.1.22']
env.hosts=['192.168.2.121']
env.passwords = {
# 'root@192.168.1.21:22': 'SKJh935yft#',
'root@192.168.2.120:22': '123456',
'root@192.168.2.121:22': '123456'
}
lpackpath="/home/install/lnmp0.9.tar.gz"
rpackpath="/tmp/install"
@task
def put_task():
run("mkdir -p /tmp/install")
with settings(warn_only=True):
result = put(lpackpath, rpackpath)
if result.failed and not confirm("put file failed, Continue[Y/N]?"):
abort("Aborting file put task!")
@task
def run_task():
with cd("/tmp/install"):
run("tar -zxvf lnmp0.9.tar.gz")
with cd("/tmp/install/root/"):
run("./centos.sh")
@task
def go():
put_task()
run_task()
结果:
[root@node110 fabric]# fab -f simple3.py go
[192.168.2.121] Executing task 'go'
[192.168.2.121] run: mkdir -p /tmp/install
[192.168.2.121] put: /home/install/lnmp0.9.tar.gz -> /tmp/install/lnmp0.9.tar.gz
[192.168.2.121] run: tar -zxvf lnmp0.9.tar.gz
[192.168.2.121] out: ./root/anaconda-ks.cfg
[192.168.2.121] out: ./root/appendonly.aof
[192.168.2.121] out: ./root/centos.sh
[192.168.2.121] out: tar: ./root/centos.sh: time stamp 2017-04-10 17:03:22 is 61.610828248 s in the future
[192.168.2.121] out: ./root/db.sql
[192.168.2.121] out: ./root/db.sql.gz
[192.168.2.121] out: ./root/dump.rdb
[192.168.2.121] out: ./root/epel-release-6-8.noarch.rpm
[192.168.2.121] out: ./root/etc/
[192.168.2.121] out: ./root/etc/passwd
[192.168.2.121] out: ./root/gmy.sh
[192.168.2.121] out: ./root/grep.log
[192.168.2.121] out: ./root/image.baidu.com/
[192.168.2.121] out: ./root/image.baidu.com/robots.txt
[192.168.2.121] out: ./root/install.log.syslog
[192.168.2.121] out: ./root/kf
[192.168.2.121] out: ./root/passwd.tar.gz
[192.168.2.121] out: ./root/q.sh
[192.168.2.121] out: ./root/remi-release-6.rpm
[192.168.2.121] out: ./root/root
[192.168.2.121] out: ./root/rsc/
[192.168.2.121] out: ./root/rsc.sh
[192.168.2.121] out: ./root/rsc.txt
[192.168.2.121] out: ./root/seqnum.sh
[192.168.2.121] out: ./root/test-position.sql
[192.168.2.121] out: ./root/test.sh
[192.168.2.121] out: ./root/test.sql
[192.168.2.121] out: ./root/test.txt
[192.168.2.121] out: ./root/tests.sql
[192.168.2.121] out:
[192.168.2.121] run: ./centos.sh
[192.168.2.121] out: 123
[192.168.2.121] out:
Done.
Disconnecting from 192.168.2.121... done.
Disconnecting from 192.168.2.120... done.
2017-04-10
网关模式文件上传与执行
评论
发表评论
姓 名: