我打算在远程服务器上使用可执行的安装脚本来执行一个
shell脚本.
test.sh:
touch test.txt
剧本:
--- - 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
当我运行该手册时,传输成功发生,但脚本不执行.
local_action在本地服务器上运行命令,而不是在hosts参数中指定的服务器上运行该命令.
原文链接:https://www.f2er.com/bash/385192.html将“执行脚本”任务更改为
- name: Execute the script command: sh /home/test_user/test.sh
它应该这样做.
您不需要在命令行中重复sudo,因为您已经在playbook中定义了sudo.
根据Ansible Intro to Playbooks用户参数在Ansys 1.4中重命名为remote_user,所以你也应该更改它
remote_user: test_user
所以,剧本将会变成:
--- - name: Transfer and execute a script. hosts: server remote_user: test_user sudo: yes tasks: - name: Transfer the script copy: src=test.sh dest=/home/test_user mode=0777 - name: Execute the script command: sh /home/test_user/test.sh