How to execute a shell script on a remote server using Ansible?

前端 未结 4 1445
一向
一向 2020-12-23 13:22

I am planning to execute a shell script on a remote server using Ansible playbook.

blank test.sh file:

touch test.sh

Playbook:

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 14:04

    You can use template module to copy if script exists on local machine to remote machine and execute it.

     - name: Copy script from local to remote machine
       hosts: remote_machine
       tasks:
        - name: Copy  script to remote_machine
          template: src=script.sh.2 dest=/script.sh mode=755
        - name: Execute script on remote_machine
          script: sh /script.sh
    

提交回复
热议问题