这似乎是一个愚蠢的问题,但我正在努力使用ansible创建一个压缩存档,然后将其复制到远程主机上。我收到一个错误,在复制任务期间目标目录/文件不存在。我已经验证了他/home/ansible-admin/app/certs目录的存在。但据我所知,压缩文件从未被创建过。
---
- hosts: example
become: yes
tasks:
- name: Create cert archive
archive:
path:
- /home/ansible-admin/app/certs
dest: /home/ansible-admin/app/app_certs.zip
format: zip
- name: Copy certs to target servers
copy:
src: /home/ansible-admin/app/app_certs.zip
dest: /home/ubuntu/app_certs.zip
owner: ubuntu
group: ubuntu
mode: "0400"
这是我一直收到的An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option fatal: [app.example.com]: FAILED! => {"changed": false, "msg": "Could not find or access '/home/ansible-admin/app_certs.zip' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}
错误消息
我希望我只是错过了一些琐碎的东西。但是看看这些文档和yaml文件,我不知道问题出在哪里。https://docs.ansible.com/ansible/latest/collections/community/general/archive_module.html
发布于 2022-09-06 19:52:04
从档案模块的文档中:
源和存档位于远程主机上,并且存档没有复制到本地主机。
我觉得这是你的问题。
如果该路径确实存在于远程主机上并创建存档,则至少副本将失败,因为控制器上不存在存档。
发布于 2022-09-07 14:50:38
正如丁克所指出的,我试图在远程主机上存档一个根本不存在的目录,而不是存档一个本地目录。我通过添加要在此之前执行的localhost
任务来解决这个问题。
- hosts: localhost
tasks:
- name: Create cert archive
archive:
path:
- /home/ansible-admin/app/certs
dest: /home/ansible-admin/app/app_certs.zip
format: zip
然后将其复制到远程服务器,并按预期的方式提取存档。
https://stackoverflow.com/questions/73627068
复制相似问题