ansible 安装部署详解(待更新)
[*]安装ansibleepel,ansibleyum -y install epel-releaseansible安装:yum -y install ansible
[*]主程序:ansibleansible-playbookansible-docansible的简单使用格式:ansible HOST-PATTERN -m MOD_NAME -a MOD_ARGS
[*]ansible的常用模块:获取模块列表:ansible-doc -lansible-doc获取帮助:ansible-doc -h-s:显示模块的参数信息例如:
1
2
3
]# ansible-doc -s ping
- name: Try to connect to host, verify a usable python and return `pong' on success.
action: ping
command模块(默认):在远程主机运行命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
]# ansible-doc -s command
- name: Executes a command on a remote node
action: command
chdir # cd into this directory before running the command
creates # a filename or (since 2.0) glob pattern, when it already exists, this step will
*not* be run.
executable # change the shell used to execute the command. Should be an absolute path to the
executable.
free_form= # the command module takes a free form command to run.There is no parameter
actually named 'free form'. See the examples!
removes # a filename or (since 2.0) glob pattern, when it does not exist, this step will
*not* be run.
warn # if command warnings are on in ansible.cfg, do not warn about this particular
line if set to no/false.
注意:command模块不支持管道
shell模块:远程主机在shell进程下运行命令,支持shell特性,如管道等
例如:
1
2
3
4
5
6
7
]# ansible all -m shell -a 'echo xin |passwd --stdin user1'
192.168.57.130 | SUCCESS | rc=0 >>
更改用户 user1 的密码 。
passwd: 所有的身份验证令牌已经成功更新。
192.168.57.128 | SUCCESS | rc=0 >>
更改用户 user1 的密码 。
passwd:所有的身份验证令牌已经成功更新。
copy模块:把本地文件拷贝到远程主机
例如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
]# ansible all -m copy -a "src=/etc/fstab dest=/tmp/fstab"
192.168.57.128 | SUCCESS => {
"changed": true,
"checksum": "96da61260bfa0930d07ba59d324a973eed9fd51f",
"dest": "/tmp/fstab",
"gid": 0,
"group": "root",
"md5sum": "0f081fe397e86456d1a14eb516c2db68",
"mode": "0644",
"owner": "root",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": 501,
"src": "/root/.ansible/tmp/ansible-tmp-1484386476.59-59078606587651/source",
"state": "file",
"uid": 0
}
192.168.57.130 | SUCCESS => {
"changed": true,
"checksum": "96da61260bfa0930d07ba59d324a973eed9fd51f",
"dest": "/tmp/fstab",
"gid": 0,
"group": "root",
"md5sum": "0f081fe397e86456d1a14eb516c2db68",
"mode": "0644",
"owner": "root",
"size": 501,
"src": "/root/.ansible/tmp/ansible-tmp-1484386477.82-55437091606538/source",
"state": "file",
"uid": 0
}
页:
[1]