要在Ansible中执行Shell脚本,可以使用Ansible的shell模块或command模块。以下是两种解决方法的示例代码:
使用shell模块:
- name: 执行Shell脚本
hosts: your_hosts
tasks:
- name: 运行Shell脚本
shell: /path/to/your/script.sh
使用command模块:
- name: 执行Shell脚本
hosts: your_hosts
tasks:
- name: 运行Shell脚本
command: /path/to/your/script.sh
在上面的示例中,您需要将"your_hosts"替换为您想要在其上执行脚本的主机或主机组的名称。您还需要将"/path/to/your/script.sh"替换为要执行的实际Shell脚本的路径。
请注意,使用shell模块或command模块执行Shell脚本需要在目标主机上具有执行权限。如果脚本没有执行权限,请使用Ansible的file模块或command模块的chmod参数来添加执行权限。