Create a var for script i.e.: script_path="/some/path/script" and use that 
instead of hard coding path
On Sunday, August 18, 2024 at 7:14:58 AM UTC-4 Yogita Patil wrote:

> Hi All,
>
> I am simply unable to execute a shell script on the remote host - this is 
> my code (all other tasks run correctly except the execute task)
>
> - name: Power consumption test
>   hosts: all
>   tasks:
>
>      - name: Transfer the script
>        ansible.builtin.copy:
>          src: power_consumption.sh
>          dest: /usr/src/power_consumption.sh
>          mode: '0777'
>
>      - name: Execute the script
> #       command: ./usr/src/power_consumption.sh
>        command: "{{ item }}"
>        args:
>          chdir: "/usr/src/"
>        with_items:
>         - "./power_consumption.sh"
>        ignore_errors: true
>
>      - name: Remove shell script from remote server
>        file:
>          path: /usr/src/power_consumption.sh
>          state: absent
>
>      - name: Copy shell script output from remote server
>        fetch:
>          src: /usr/src/{{ ansible_fqdn }}.txt
>          dest: /usr/src
>          mode: '0777'
>          with_fileglob:
>           _ "*.txt"
>
>
> I have also tried with the shell: , script: sh ways of executing the 
> script and none of them work, can someone tell me what I am doing wrong? 
> TIA.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8da4e506-2504-4724-b4e9-c1d45c61800dn%40googlegroups.com.

Reply via email to