# Ansible execute remote shell script with source to other files

**URL:** <https://forum.ansible.com/t/ansible-execute-remote-shell-script-with-source-to-other-files/36317>\
**Category:** Ansible Project\
**Created:** [February 10, 2022, 1:48pm UTC](https://forum.ansible.com/t/ansible-execute-remote-shell-script-with-source-to-other-files/36317 "2022-02-10T13:48:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emanuel\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/e/b3f665/32.png) [@Emanuel\_Gonzalez](https://forum.ansible.com/u/Emanuel_Gonzalez)\
**Post date:** [February 10, 2022, 1:48pm UTC](https://forum.ansible.com/t/ansible-execute-remote-shell-script-with-source-to-other-files/36317/1 "2022-02-10T13:48:54Z")

</div>

Hello,  
I’m trying to run a playbook which executes a shell script in a remote instance.

Playbook

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 10, 2022, 2:56pm UTC](https://forum.ansible.com/t/ansible-execute-remote-shell-script-with-source-to-other-files/36317/2 "2022-02-10T14:56:35Z")

</div>

> Hello,  
> I’m trying to run a playbook which executes a shell script in a remote instance.
> 
> Playbook  
> ---  
> - name: Test SH  
> hosts: schedule-dev  
> become: yes  
> gather\_facts: no  
> tasks:  
> - name: Test Shell Ansible  
> shell: |  
> sh create\_partition\_db.sh {{ carrier }}  
> args:  
> chdir: /opt/app/automation  
> executable: /bin/bash  
> register: output  
> - name: ouput  
> debug:  
> var: output.stdout  
> The value of the variable {{ carrier }} is sent through the command line:
> 
> ansible-playbook -i hosts-dev --extra-vars "carrier=dev" playbook/step-2.yaml
> 
> When I run the playbook I see this error:
> 
> fatal: [schedule01-dev]: FAILED! =\> {"ansible\_facts": {"discovered\_interpreter\_python": "/usr/bin/python"}, "changed": true, "cmd": "sh create\_partition\_db.sh 00CN\n", "delta": "0:00:00.003453", "end": "2022-02-10 13:27:23.244718", "msg": "non-zero return code", "rc": 2, "start": "2022-02-10 13:27:23.241265", "stderr": "create\_partition\_db.sh: 3: create\_partition\_db.sh: source: not found\ncreate\_partition\_db.sh: 4: create\_partition\_db.sh: source: not found\ncreate\_partition\_db.sh: 6: create\_partition\_db.sh: get\_partitions: not found\ncreate\_partition\_db.sh: 8: create\_partition\_db.sh: function: not found\ncreate\_partition\_db.sh: 34: create\_partition\_db.sh: Syntax error: \"}\" unexpected", "stderr\_lines": ["create\_partition\_db.sh: 3: create\_partition\_db.sh: source: not found", "create\_partition\_db.sh: 4: create\_partition\_db.sh: source: not found", "create\_partition\_db.sh: 6: create\_partition\_db.sh: get\_partitions: not found", "create\_partition\_db.sh: 8: create\_partition\_db.sh: function: not found", "create\_partition\_db.sh: 34: create\_partition\_db.sh: Syntax error: \"}\" unexpected"], "stdout": "", "stdout\_lines": }
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> schedule01-dev : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0  
> When I run the script from the instance I don’t see any errors, I think it has to do with the fact that in the script I use the source command to call other files:
> 
> #!/bin/bash
> 
> source config-dev.cfg  
> source functions.sh
> 
> Any sugestion?

Looks like the default shell on the target doesn't know about "source". Use "." instead or force the usage of bash with:

&nbsp;&nbsp;&nbsp;executable: "/bin/bash"

in your shell task.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Emanuel\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/e/b3f665/32.png) [@Emanuel\_Gonzalez](https://forum.ansible.com/u/Emanuel_Gonzalez)\
**Post date:** [February 10, 2022, 3:15pm UTC](https://forum.ansible.com/t/ansible-execute-remote-shell-script-with-source-to-other-files/36317/3 "2022-02-10T15:15:03Z")

</div>

I changed source by “.” inside the shell script and it’s still not running.

#!/bin/bash

. config-dev.cfg  
. functions.sh

Within the playbook I am already using the parameter “executable: /bin/bash”.

Playbook

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 10, 2022, 3:24pm UTC](https://forum.ansible.com/t/ansible-execute-remote-shell-script-with-source-to-other-files/36317/4 "2022-02-10T15:24:00Z")

</div>

> I changed source by "." inside the shell script and it’s still not running.
> 
> #!/bin/bash
> 
> . config-dev.cfg  
> . functions.sh
> 
> Within the playbook I am already using the parameter "executable: /bin/bash".

That's true, but you again calling the shell again with "sh ..". Makes no sense to me.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
