Score:0

script file is not getting executed on target machine using ansible script module

na flag

script file is not getting executed on target machine using ansible script module.

I have written a script file on control-node wants that to copy it on target machine and then from there i wants to run the script file using ansible script module.

playbook:
---
- name: execute script file on target
  hosts: all
  tasks:
    - name: copy script file
      copy:
        src: /home/ansibleuser/practice-ansible/pre-check.sh
        dest: /home/ansibleuser/
        mode: 0777
    - name: execute the script on destination servers
      script:
        cmd: /home/ansibleuser/pre-check.sh
      args:
       removes: /home/ansibleuser/pre-check.sh
      register: output
Error:
"changed": false,
    "msg": "Could not find or access '/home/ansibleuser/pre-check.sh' on the Ansible Controller.
If you are using a module and expect the file to exist on the remote, see the remote_src option"
ws flag
Welcome to stackoverflow - you might find this helpful: https://stackoverflow.com/editing-help
Score:1
pt flag

The error message seems pretty clear. The script module works by first (a) copying the mentioned script from the control host (your local system) to the remote system and then (b) running it.

You don't need your copy task. You just need to fix the path in the script module:

- name: execute script file on target
  hosts: all
  tasks:
    - name: execute the script on destination servers
      script:
        cmd: /home/ansibleuser/practice-ansible/pre-check.sh
      register: output
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.