Fabric 学习笔记
来源:互联网 发布:java ffmpeg 视频转码 编辑:程序博客网 时间:2024/05/23 20:46
转载源:http://my.oschina.net/guol/blog/97607
前面学习了理论,下面该练练手了。两台机器:10.1.6.186、10.1.6.159。fabric部署在10.1.6.186上面。
1 执行一个简单的task任务,显示两台机器的/home/guol/目录下的文件
01
#!/usr/bin/python
02
from
fabric.api
import
*
03
from
fabric.context_managers
import
*
04
05
env.hosts
=
[
'10.1.6.186'
,
'10.1.6.159'
]
06
env.password
=
'xxxxxx'
07
08
def
task1():
09
with cd(
'/home/guol'
):
10
run(
'ls -l'
)
11
12
##结果
13
root@vm11:
/
tmp
# fab task1
14
[
10.1
.
6.186
] Executing task
'task1'
15
[
10.1
.
6.186
] run: ls
-
l
16
[
10.1
.
6.186
] out: total
0
17
[
10.1
.
6.186
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
186
-
local
18
[
10.1
.
6.186
] out:
19
20
[
10.1
.
6.159
] Executing task
'task1'
21
[
10.1
.
6.159
] run: ls
-
l
22
[
10.1
.
6.159
] out: total
0
23
[
10.1
.
6.159
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
159
-
remote
24
[
10.1
.
6.159
] out:
25
26
27
Done.
28
Disconnecting
from
10.1
.
6.159
... done.
29
Disconnecting
from
10.1
.
6.186
... done.
01
#!/usr/bin/python
02
from
fabric.api
import
*
03
from
fabric.context_managers
import
*
04
05
env.hosts
=
[
'10.1.6.186'
,
'10.1.6.159'
]
06
env.password
=
'xxxxxx'
07
env.exclude_hosts
=
[
'10.1.6.159'
]
08
09
def
task1():
10
with cd(
'/home/guol'
):
11
run(
'ls -l'
)
12
13
##执行
14
root@vm11:
/
tmp
# fab task1
15
[
10.1
.
6.186
] Executing task
'task1'
16
[
10.1
.
6.186
] run: ls
-
l
17
[
10.1
.
6.186
] out: total
0
18
[
10.1
.
6.186
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
186
-
local
19
[
10.1
.
6.186
] out:
20
21
22
Done.
23
Disconnecting
from
10.1
.
6.186
... done.
01
#!/usr/bin/python
02
from
fabric.api
import
*
03
from
fabric.colors
import
*
04
from
fabric.context_managers
import
*
05
06
env.hosts
=
[
'10.1.6.186'
,
'10.1.6.159'
]
07
env.password
=
'xxxxxx'
08
env.exclude_hosts
=
[
'10.1.6.159'
]
09
10
11
def
task1():
12
with cd(
'/home/guol'
):
13
run(
'ls -l'
)
14
15
def
task2():
16
print
(green(
"I'm fabric"
))
17
18
def
deploy():
19
execute(task1)
20
execute(task2)
21
22
##执行
23
root@vm11:
/
tmp
# fab deploy
24
[
10.1
.
6.186
] Executing task
'deploy'
25
[
10.1
.
6.186
] Executing task
'task1'
26
[
10.1
.
6.186
] run: ls
-
l
27
[
10.1
.
6.186
] out: total
0
28
[
10.1
.
6.186
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
186
-
local
29
[
10.1
.
6.186
] out:
30
31
[
10.1
.
6.186
] Executing task
'task2'
32
I'm fabric
33
34
Done.
35
Disconnecting
from
10.1
.
6.186
... done.
01
#!/usr/bin/python
02
from
fabric.api
import
*
03
from
fabric.colors
import
*
04
from
fabric.context_managers
import
*
05
06
env.roledefs
=
{
'web1'
:[
'10.1.6.186'
],
'web2'
:[
'10.1.6.159'
]}
07
env.password
=
'xxxxxx'
08
09
@roles
(
'web1'
)
10
def
task1():
11
with cd(
'/home/guol'
):
12
run(
'ls -l'
)
13
@roles
(
'web2'
)
14
def
task2():
15
print
(green(
"I'm fabric"
))
16
17
def
deploy():
18
execute(task1)
19
execute(task2)
20
##执行
21
root@vm11:
/
tmp
# fab deploy
22
[
10.1
.
6.186
] Executing task
'task1'
23
[
10.1
.
6.186
] run: ls
-
l
24
[
10.1
.
6.186
] out: total
0
25
[
10.1
.
6.186
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
186
-
local
26
[
10.1
.
6.186
] out:
27
28
[
10.1
.
6.159
] Executing task
'task2'
29
I'm fabric
30
31
Done.
32
Disconnecting
from
10.1
.
6.186
... done.
01
#!/usr/bin/python
02
from
fabric.api
import
*
03
from
fabric.colors
import
*
04
from
fabric.context_managers
import
*
05
env.hosts
=
[
'10.1.6.159'
]
06
env.password
=
'xxxxxx'
07
08
def
task1():
09
print
(green(
"I'm 186 /home/guol/"
))
10
local(
'ls -l /home/guol'
)
11
def
task2():
12
print
(green(
"I'm get 159's 159-remote file to 186"
))
13
get(
'/home/guol/159-remote'
,
'/home/guol'
)
14
print
(yellow(
"I'm 186 /home/guol/"
))
15
local(
'ls -l /home/guol'
)
16
17
def
deploy():
18
execute(task1)
19
execute(task2)
20
21
##执行
22
root@vm11:
/
tmp
# fab deploy
23
[
10.1
.
6.159
] Executing task
'deploy'
24
[
10.1
.
6.159
] Executing task
'task1'
25
I'm
186
/
home
/
guol
/
26
[localhost] local: ls
-
l
/
home
/
guol
27
total
0
28
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
186
-
local
29
[
10.1
.
6.159
] Executing task
'task2'
30
I
'm get 159'
s
159
-
remote
file
to
186
31
[
10.1
.
6.159
] download:
/
home
/
guol
/
159
-
remote <
-
/
home
/
guol
/
159
-
remote
32
I'm
186
/
home
/
guol
/
33
[localhost] local: ls
-
l
/
home
/
guol
34
total
0
35
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
14
:
28
159
-
remote
36
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
186
-
local
37
38
Done.
39
Disconnecting
from
10.1
.
6.159
... done.
01
#!/usr/bin/python
02
from
fabric.api
import
*
03
from
fabric.colors
import
*
04
from
fabric.context_managers
import
*
05
env.hosts
=
[
'10.1.6.159'
]
06
env.password
=
'xxxxxx'
07
08
def
task1():
09
print
(green(
"I'm 159 /home/guol/"
))
10
with cd(
'/home/guol'
):
11
run(
'ls -l'
)
12
def
task2():
13
print
(green(
"I'm put 186's 186-local file to 159"
))
14
put(
'/home/guol/186-local'
,
'/home/guol'
)
15
print
(yellow(
"I'm 159 /home/guol/"
))
16
with cd(
'/home/guol'
):
17
run(
'ls -l'
)
18
def
deploy():
19
execute(task1)
20
execute(task2)
21
22
##执行
23
root@vm11:
/
tmp
# fab deploy
24
[
10.1
.
6.159
] Executing task
'deploy'
25
[
10.1
.
6.159
] Executing task
'task1'
26
I'm
159
/
home
/
guol
/
27
[
10.1
.
6.159
] run: ls
-
l
28
[
10.1
.
6.159
] out: total
0
29
[
10.1
.
6.159
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
159
-
remote
30
[
10.1
.
6.159
] out:
31
32
[
10.1
.
6.159
] Executing task
'task2'
33
I
'm put 186'
s
186
-
local
file
to
159
34
[
10.1
.
6.159
] put:
/
home
/
guol
/
186
-
local
-
>
/
home
/
guol
/
186
-
local
35
I'm
159
/
home
/
guol
/
36
[
10.1
.
6.159
] run: ls
-
l
37
[
10.1
.
6.159
] out: total
0
38
[
10.1
.
6.159
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
13
:
32
159
-
remote
39
[
10.1
.
6.159
] out:
-
rw
-
r
-
-
r
-
-
1
root root
0
Dec
21
14
:
33
186
-
local
40
[
10.1
.
6.159
] out:
41
42
43
Done.
44
Disconnecting
from
10.1
.
6.159
... done.
01
#!/usr/bin/python
02
from
fabric.api
import
*
03
from
fabric.colors
import
*
04
from
fabric.context_managers
import
*
05
env.hosts
=
[
'10.1.6.159'
]
06
env.password
=
'xxxxxx'
07
08
def
task3():
09
open_shell(
"ifconfig eth0|grep '10.1.6.159'"
)
10
def
deploy():
11
execute(task3)
12
13
##执行
14
root@vm11:
/
tmp
# fab deploy
15
[
10.1
.
6.159
] Executing task
'deploy'
16
[
10.1
.
6.159
] Executing task
'task3'
17
Welcome to Ubuntu
12.10
(GNU
/
Linux
3.5
.
0
-
17
-
generic x86_64)
18
Last login: Fri Dec
21
14
:
39
:
39
2012
from
10.1
.
6.186
19
ifconfig eth0|grep
'10.1.6.159'
20
root@vm12:~
# ifconfig eth0|grep '10.1.6.159'
21
inet addr:
10.1
.
6.159
Bcast:
10.1
.
6.255
Mask:
255.255
.
255.0
- fabric学习笔记
- fabric 学习笔记
- Fabric 学习笔记
- Fabric.js学习笔记
- Mysql Fabric实现学习笔记
- Fabric-Windows环境-学习笔记
- Hyperledger fabric 学习笔记: fabric v1.0 代码结构
- fabric学习
- Hyperledger fabric 学习笔记: go语言 与 JSON
- fabric学习资料
- python Fabric库学习
- Fabric 学习小结
- fabric发布函数学习
- Fabric.js的学习
- fabric
- fabric
- fabric
- Fabric
- 【Android】异步加载网络图片!!!!
- jsp中The absolute uri: http://java.sun.com/jsp/jstl/core出问题
- 思考与总结【0】:持续不断的思考
- 动态控制表格insertRow,insertCell()
- Java读取数据进行equals比较不相等
- Fabric 学习笔记
- 写五子棋游戏有感
- 相关关系与因果关系之探讨——大数据时代读后感(1)
- hdu oj 2018
- 堆排
- 初识shell编程
- DNS FAILOVER SETTING
- 谨慎使用String作为HashMap的Key
- UVA10413 Crazy Savages 扩展欧几里德的应用