【发布时间】:2020-02-02 04:13:24
【问题描述】:
使用 Ansible,我希望使用当前时间戳和 755 权限将所有文件从 redhat localhost /app/tmpfiles/ 文件夹传输到位置 /was/IBM/BACKUP/00005/ 的 remoteaixhost
以下命令显示我的本地主机上确实有一个文件:
[localuser@localhost]$ ls -ltr /app/tmpfiles/*
-rw-rw-r-- 1 localuser user 12 Sep 13 15:53 /app/tmpfiles/testingjsp4.jsp
以下是我针对此任务的 ansible playbook。
- name: Play 1
host: remoteaixhost
- name: "Backup on Destination Server"
tags: validate
local_action: command rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "--out-format=<<CHANGED>>%i %n%L" "{{ playbook_dir }}/tmpfiles/*" "{{ USER }}@{{ inventory_hostname }}":"{{ vars[inventory_hostname] }}/BACKUP/{{ Number }}/"
run_once: true
上面的 playbook 运行失败,下面是 ansible 的错误日志:
TASK [在目标服务器 remoteaixhost 上备份。] *** 致命: [remoteaixhost -> 本地主机]:失败! => {“改变”:真,“cmd”: [“rsync”,“--delay-updates”,“-F”,“--compress”,“--chmod=755”, "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null", "--out-format=%i %n%L", "/app/tmpfiles/", “user2@remoteaixhost:/was/IBM/BACKUP/00005/”],“增量”: “0:00:00.228097”,“结束”:“2019-10-04 00:23:09.103525”,“味精”: “非零返回码”,“rc”:23,“start”:“2019-10-04 00:23:08.875428", "stderr": "警告:永久添加 'remoteaixhost' (RSA) 到已知主机列表。\r\n此系统是 仅供授权用户使用。使用此计算机的个人 未经授权或越权的系统,均受制于 对他们在这个系统上的所有活动进行监控和 由系统人员记录。在监视个人的过程中 不当使用本系统,或在系统维护过程中, 还可以监控授权用户的活动。任何人使用 该系统明确同意此类监控,并被告知 如果这种监测揭示了可能的犯罪证据 活动,系统人员可以提供这种监控的证据 执法人员\nrsync: link_stat \"/app/tmpfiles/\" 失败:没有这样的文件或目录 (2)\nrsync 错误:一些文件/属性 未在 main.c(1178) 转移(参见先前的错误)(代码 23) [sender=3.1.2]", "stderr_lines": ["警告:永久添加 'remoteaixhost' (RSA) 到已知主机列表。", "此系统是 仅供授权用户使用。使用此计算机的个人 未经授权或越权的系统,均受制于 对他们在这个系统上的所有活动进行监控和 由系统人员记录。在监视个人的过程中 不当使用本系统,或在系统维护过程中, 还可以监控授权用户的活动。任何人使用 该系统明确同意此类监控,并被告知 如果这种监测揭示了可能的犯罪证据 活动,系统人员可以提供这种监控的证据 给执法人员”,“rsync:link_stat \"/app/tmpfiles/*\" 失败:没有这样的文件或目录 (2)", "rsync 错误:某些文件/属性未传输(请参阅以前的错误) (code 23) at main.c(1178) [sender=3.1.2]"], "stdout": "", “stdout_lines”:[]}
没有更多的主机了
播放回顾 ****************************************************** ******************* remoteaixhost : 好的=8 已更改=4 无法访问=0
失败=1 跳过=6 获救=0 忽略=0 本地主机
: 好的=4 已更改=2 无法访问=0 失败=0 已跳过=1
获救=0 忽略=0构建步骤 'Execute shell' 将构建标记为失败 Finished: FAILURE
在输出中困扰我的一件事是“致命:[remoteaixhost -> localhost]”。为什么当我们实际指定 local_action 时它会说“remoteaixhost -> localhost”,而我希望它显示如下:“本地主机-> remoteaixhost" 但是,我不确定我的观察是否有关,解决方案是什么,以及这是否有助于我们寻找正确的方向。
注意:我还尝试从上面的 rsync 命令中删除 astrick,如下所示:
rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "--out-format=<<CHANGED>>%i %n%L" "{{ playbook_dir }}/tmpfiles/" "{{ USER }}@{{ inventory_hostname }}":"{{ vars[inventory_hostname] }}/BACKUP/{{ Number }}/"
但是没有收到错误,文件没有被复制到目标主机。
我尝试在本地主机上手动运行由 ansible 生成的 rsync 命令,以下是观察结果:
# with aistrick the copy is successful:
[localuser@localhost]$ rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --out-format="<<CHANGED>>%i %n%L" /app/tmpfiles/* user2@remoteaixhost:/was/IBM/BACKUP/00005/
Warning: Permanently added 'remoteaixhost' (RSA) to the list of known hosts.
This system is for the use of authorized users only. Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel. In the course of monitoring individuals improperly using this system, or in the course of system maintenance, the activities of authorized users may also be monitored. Anyone using this system expressly consents to such monitoring and is advised that if such such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to the law enforcement officials
<<CHANGED>><f+++++++++ testingjsp4.jsp
[localuser@localhost]$ echo $?
0
# without aistrick the files do not get copied over:
[localuser@localhost]$ rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --out-format="<<CHANGED>>%i %n%L" /app/tmpfiles/ user2@remoteaixhost:/was/IBM/BACKUP/00005/
Warning: Permanently added 'remoteaixhost' (RSA) to the list of known hosts.
This system is for the use of authorized users only. Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel. In the course of monitoring individuals improperly using this system, or in the course of system maintenance, the activities of authorized users may also be monitored. Anyone using this system expressly consents to such monitoring and is advised that if such such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to the law enforcement officials
skipping directory .
[localuser@localhost]$ echo $?
0
你能推荐一下吗?
【问题讨论】:
-
在运行
rsync命令时可以尝试使用shell模块而不是command模块吗? -
我明天可以试试,但是,您是否在我的剧本中看到任何问题或在输出中看到任何相关内容?
-
我个人没有发现任何相关内容。我唯一对
shell模块感到好奇的是*当您使用shell 时才有意义。command模块似乎无法处理*。 -
@Pacifist 遗憾的是,这甚至不适用于 shell 模块。我收到相同的错误消息,即执法人员”,“rsync:link_stat \”/app/tmpfiles/*\”失败:没有这样的文件或目录(2)”,“rsync 错误:有人可以解决问题吗
-
我的回答对你有用吗?