ansible使用3--模块的概念

模块的概念

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"
		}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值