可能是Ansible使用的路径与手动运行时的路径不一致导致的。可以尝试在Ansible playbook中设置适当的路径,比如使用绝对路径而不是相对路径。另外,也可以在脚本中使用完整路径来保证正确性。例如:
或者:
此外,还可以在Ansible playbook中添加debug模块来进一步定位问题所在:
name: Run script shell: "/path/to/script.sh" register: script_output
debug: var: script_output # 打印脚本输出以定位问题
通过这些方法,可以解决Ansible运行脚本时的'找不到文件或目录”的问题。