Ansible execute remote shell script with source to other files

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

Playbook

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:

   executable: "/bin/bash"

in your shell task.

Regards
        Racke

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

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
         Racke