模块的概念
1 笼统查看所有模块说明
[root@self1-centos7-2 11:06:16 /etc/ansible]#ansible-doc -l
a10_server Manage A10 Networks AX/SoftAX/Thunder/vThunder devices' server object
a10_server_axapi3 Manage A10 Networks AX/SoftAX/Thunder/vThunder devices
a10_service_group Manage A10 Networks AX/SoftAX/Thunder/vThunder devices' service groups
a10_virtual_server Manage A10 Networks AX/SoftAX/Thunder/vThunder devices' virtual servers
aci_aaa_user
...........
........
2 精细查看某个模块说明
[root@self1-centos7-2 11:13:36 /etc/ansible]#ansible-doc -s ping
- name: Try to connect to host, verify a usable python and return `pong' on success
ping:
data: # Data to return for the `ping' return value. If this parameter is set to `crash', the module will cause an exception.
fetch模块的内容就比较多了,从远程节点拿取文件
[root@self1-centos7-2 11:13:55 /etc/ansible]#ansible-doc -s fetch
- name: Fetch files from remote nodes
fetch:
dest: # (required) A directory to save the file into. For example, if the `dest' directory is `/backup' a `src' file named
`/etc/profile' on host `host.example.com', would be saved into
`/backup/host.example.com/etc/profile'. The host name is based on the inventory name. 本地目录 必须有的
fail_on_missing: # When set to `yes', the task will fail if the remote file cannot be read for any reason. Prior to Ansible 2.5, setting
this would only fail if the source file was missing. The default was changed to `yes' in
Ansible 2.5.
flat: # Allows you to override the default behavior of appending hostname/path/to/file to the destination. If `dest' ends with
'/', it will use the basename of the source file, similar to the copy module. Obviously
this is only handy if the filenames are unique.
src: # (required) The file on the remote system to fetch. This `must' be a file, not a directory. Recursive fetching may be
supported in a later release. 远程目录 必须有的
validate_checksum: # Verify that the source and destination checksums match after the files are fetched.
测试fetch模块
[root@self1-centos7-2 11:23:14 /]#ansible web -m fetch -a "src=/etc/fstab dest=/test"
10.2.0.7 | CHANGED => {
"changed": true,
"checksum": "98401d143c55c4fbcd6d677722df7ed51903fcef",
"dest": "/test/10.2.0.7/etc/fstab", //自动建了相应目录
"md5sum": "800328aef6099afd0c18be87dc594ae4",
"remote_checksum": "98401d143c55c4fbcd6d677722df7ed51903fcef",
"remote_md5sum": null
}
self2-1 | CHANGED => {
"changed": true,
"checksum": "98401d143c55c4fbcd6d677722df7ed51903fcef",
"dest": "/test/self2-1/etc/fstab",
"md5sum": "800328aef6099afd0c18be87dc594ae4",
"remote_checksum": "98401d143c55c4fbcd6d677722df7ed51903fcef",
"remote_md5sum": null
}
[root@self1-centos7-2 11:26:04 /test/self2-1/etc]#cat fstab
#
# /etc/fstab
# Created by anaconda on Mon Jan 28 20:51:49 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f41e390f-835b-4223-a9bb-9b45984ddf8d / xfs defaults 0 0
幂等性验证,再次执行,ansible知道的拉取得文件已经存在(通过哈希值判断,因此有改动也会覆盖),就不会重复执行,返回结果为绿色(上次为黄色),并且 changed字段由true变成了false
[root@self1-centos7-2 11:26:10 /test/self2-1/etc]#ansible web -m fetch -a "src=/etc/fstab dest=/test"
10.2.0.7 | SUCCESS => {
"changed": false, //注意这里
"checksum": "98401d143c55c4fbcd6d677722df7ed51903fcef",
"dest": "/test/10.2.0.7/etc/fstab",
"file": "/etc/fstab",
"md5sum": "800328aef6099afd0c18be87dc594ae4"
}
self2-1 | SUCCESS => {
"changed": false,
"checksum": "98401d143c55c4fbcd6d677722df7ed51903fcef",
"dest": "/test/self2-1/etc/fstab",
"file": "/etc/fstab",
"md5sum": "800328aef6099afd0c18be87dc594ae4"
}