欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ansible:fetch的使用

程序员文章站 2022-04-26 08:33:02
...


1. ansible功能查看方法

 [[email protected] ~]# 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.

2. fetch

ansible:fetch的使用

 [[email protected] ansible]# vim hosts
[testA]
server5 ansible_host=172.25.60.5
server6 ansible_host=172.25.60.6
[testB]
server3 ansible_host=172.25.60.3
[test:children]
testA
testB
[[email protected] ansible]# ansible testA -m fetch -a "src=/etc/fstab dest=/testdir/ansible"  # 将testA组中主机的/etc/fstab拷贝到ansible主机的/testdir/ansible目录下
server6 | CHANGED => {
    "changed": true, 
    "checksum": "0d7e74cb0ef4387d8c0be3c03cae65073b719404", 
    "dest": "/testdir/ansible/server6/etc/fstab", 
    "md5sum": "df6584fd3c643b1ad71247ed8ea368dc", 
    "remote_checksum": "0d7e74cb0ef4387d8c0be3c03cae65073b719404", 
    "remote_md5sum": null
}
server5 | CHANGED => {
    "changed": true, 
    "checksum": "0d7e74cb0ef4387d8c0be3c03cae65073b719404", 
    "dest": "/testdir/ansible/server5/etc/fstab", 
    "md5sum": "df6584fd3c643b1ad71247ed8ea368dc", 
    "remote_checksum": "0d7e74cb0ef4387d8c0be3c03cae65073b719404", 
    "remote_md5sum": null
}
[[email protected] ansible]# cd /testdir/ansible/
[[email protected] ansible]# ls
server5  server6

幂等性的体现

[[email protected] ansible]# ansible testA -m fetch -a "src=/etc/fstab dest=/testdir/ansible"
server5 | SUCCESS => {
    "changed": false, 
    "checksum": "0d7e74cb0ef4387d8c0be3c03cae65073b719404", 
    "dest": "/testdir/ansible/server5/etc/fstab", 
    "file": "/etc/fstab", 
    "md5sum": "df6584fd3c643b1ad71247ed8ea368dc"
}
server6 | SUCCESS => {
    "changed": false, 
    "checksum": "0d7e74cb0ef4387d8c0be3c03cae65073b719404", 
    "dest": "/testdir/ansible/server6/etc/fstab", 
    "file": "/etc/fstab", 
    "md5sum": "df6584fd3c643b1ad71247ed8ea368dc"
相关标签: linuz企业实战