相关疑难解决方法(0)

如何使用Ansible在远程服务器上执行shell脚本?

我打算使用Ansible playbook在远程服务器上执行shell脚本.

test.sh:

touch test.txt
Run Code Online (Sandbox Code Playgroud)

剧本:

---
- name: Transfer and execute a script.
  hosts: server
  user: test_user
  sudo: yes
  tasks:
     - name: Transfer the script
       copy: src=test.sh dest=/home/test_user mode=0777

     - name: Execute the script
       local_action: command sudo sh /home/test_user/test.sh
Run Code Online (Sandbox Code Playgroud)

当我运行playbook时,传输成功,但脚本没有执行.

shell remote-server ansible ansible-playbook

48
推荐指数
4
解决办法
14万
查看次数

标签 统计

ansible ×1

ansible-playbook ×1

remote-server ×1

shell ×1