使用 ansible 从远程 src 路径获取到本地几个主机上的相同路径

使用 ansible 从远程 src 路径获取到本地几个主机上的相同路径

使用copyfetch,较新的主机目录会覆盖较早的目录。我希望每个目录都位于相同的本地路径下,也许使用主机特定信息作为后缀。

ansile aid -m copy -a "src=/data/logs/app dest=logs remote_src=true" 

ansible 用于一堆机器,应该有一种方法可以区分copy每台机器。

答案1

复制

remote_src=true按照说明操作。源码从远程主机并将其复制到目的地在远程主机上

shell> ansible test_11 -m copy -a "src=/etc/passwd dest=/tmp/ansible/copy remote_src=true"
test_11 | CHANGED => {
    "changed": true,
    "checksum": "2b1ed1b1cbe2a44c68148a61fed0812b9aa385fb",
    "dest": "/tmp/ansible/copy/passwd",
    "gid": 0,
    "group": "wheel",
    "md5sum": "f8ef74e8767c3692d622dd94ffde7000",
    "mode": "0644",
    "owner": "root",
    "size": 1888,
    "src": "/etc/passwd",
    "state": "file",
    "uid": 0
}
shell> ssh admin@test_11 ls -la /tmp/ansible/copy
total 6
drwxr-xr-x  2 root  wheel     3 Oct 16 06:50 .
drwxr-xr-x  3 root  wheel     3 Oct 16 06:50 ..
-rw-r--r--  1 root  wheel  1888 Jan 11  2023 passwd

shell> ssh admin@test_11 md5 /tmp/ansible/copy/passwd
MD5 (/tmp/ansible/copy/passwd) = f8ef74e8767c3692d622dd94ffde7000

拿来

也做了它所说的。它获取源码从远程主机到目的地在控制器处

shell> ansible test_11 -m fetch -a "src=/etc/passwd dest=/tmp/ansible/fetch"
test_11 | CHANGED => {
    "changed": true,
    "checksum": "2b1ed1b1cbe2a44c68148a61fed0812b9aa385fb",
    "dest": "/tmp/ansible/fetch/test_11/etc/passwd",
    "md5sum": "f8ef74e8767c3692d622dd94ffde7000",
    "remote_checksum": "2b1ed1b1cbe2a44c68148a61fed0812b9aa385fb",
    "remote_md5sum": null
}
shell> ls -la /tmp/ansible/fetch/test_11/etc/
total 12
drwxrwxr-x 2 vlado vlado 4096 Oct 16 08:53 .
drwxrwxr-x 3 vlado vlado 4096 Oct 16 08:53 ..
-rw-rw-r-- 1 vlado vlado 1888 Oct 16 08:53 passwd

shell> md5sum /tmp/ansible/fetch/test_11/etc/passwd 
f8ef74e8767c3692d622dd94ffde7000  /tmp/ansible/fetch/test_11/etc/passwd

相关内容