ubuntu - 无法通过 ansible 运行 .sh 文件
问题描述
我有 ubuntu 服务器设置,我想在其中执行 shell 脚本。我尝试了以下代码,但没有运气。
ansible.yml 文件:
- hosts: testserver
remote_user: ubuntu
become: yes
tasks:
- name: copy files and execute it
script: /media/anish/linux_files/ansible-terraform/play.sh
play.sh 文件:
#!bin/sh
echo 'hello'
它给出以下错误:
fatal: [13.213.12.27]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 127, "stderr": "Shared connection to 13.213.12.27 closed.\r\n", "stderr_lines": ["Shared connection to 13.213.12.27 closed."], "stdout": "/bin/sh: 1: /home/ubuntu/.ansible/tmp/ansible-tmp-1617116935.2170017-256995291519228/play.sh: not found\r\n", "stdout_lines": ["/bin/sh: 1: /home/ubuntu/.ansible/tmp/ansible-tmp-1617116935.2170017-256995291519228/play.sh: not found"]}
但是,我可以通过其他方式执行它:通过复制命令将文件复制到服务器并在那里执行。但是这种方法有什么问题呢?
解决方案
但是,我可以通过其他方式执行它:通过复制命令将文件复制到服务器并在那里执行。但是这种方法有什么问题呢?
如果要在目的主机上运行,需要先复制脚本。
如果您宁愿在运行 Ansible 的主机上本地运行它,则需要添加
delegate_to: localhost
- hosts: testserver
remote_user: ubuntu
become: yes
tasks:
- name: copy files and execute it
script: /media/anish/linux_files/ansible-terraform/play.sh
delegate_to: localhost
推荐阅读
- node.js - 在文件更改时转译 ES6 并启动 Express 应用程序
- postgresql - 将字符更改为时间戳
- javascript - TypeError: undefined is not an object - 使用 forEach 评估数组时
- java - 扫描仪+开关使用
- swift - 访问所有数组元素的子节点
- android - 当我尝试调试时,为什么 Android Studio 会打开 looper.java?
- javascript - 如何使用 data-url 打开下一个模式?
- java - Taskmanager 转储 - 可以使用 java/eclipse 内存分析器进行分析吗?
- php - 带有编程代码的文本区域内容未插入数据库
- reactjs - React Routes 受保护的路由