title: How to execute a shell script on a remote server using Ansible?
body: <p>I am planning to execute a shell script on a remote server using Ansible playbook.</p>
  
  <p>blank test.sh file:</p>
  
  <pre><code>touch test.sh
  </code></pre>
  
  <p>Playbook:</p>
  
  <pre><code>---
  - 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
  </code></pre>
  
  <p>When I run the playbook, the transfer successfully occurs but the script is not executed.</p>