可以使用ansible的shell模块来执行shell脚本,也可以在playbook中使用command或raw模块。

  1. 使用shell模块

在playbook中使用shell模块可以执行本地或远程的shell脚本,示例:

- name: Execute shell script
  hosts: webserver
  tasks:
    - name: Execute shell script
      shell: /path/to/script.sh
  1. 使用command模块

command模块可以执行本地或远程的命令,示例:

- name: Execute shell script with command module
  hosts: webserver
  tasks:
    - name: Execute shell script with command module
      command: /path/to/script.sh
  1. 使用raw模块

raw模块可以直接执行命令,示例:

- name: Execute shell script with raw module
  hosts: webserver
  tasks:
    - name: Execute shell script with raw module
      raw: /path/to/script.sh

需要注意的是,使用raw模块时要确保被执行的命令在远程主机上是可用的,否则可能会导致执行失败。

ansible-playbook 执行shell脚本

原文地址: http://www.cveoy.top/t/topic/yLl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录