On 10/02/2022 16:15, SysAdmin EM wrote:
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
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 On Thu, Feb 10, 2022 at 11:56 AM Stefan Hornburg (Racke) <ra...@linuxia.de <mailto:ra...@linuxia.de>> wrote: On 10/02/2022 14:48, SysAdmin EM wrote: > 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 > > -- > 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 ansible-project+unsubscr...@googlegroups.com <mailto:ansible-project%2bunsubscr...@googlegroups.com> <mailto:ansible-project+unsubscr...@googlegroups.com <mailto:ansible-project%2bunsubscr...@googlegroups.com>>. > To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGUDtn%3DHeuyr5kyXPYODJKCvn06d6QhmMne9USsxWxD%3D8O%2B-zw%40mail.gmail.com <https://groups.google.com/d/msgid/ansible-project/CAGUDtn%3DHeuyr5kyXPYODJKCvn06d6QhmMne9USsxWxD%3D8O%2B-zw%40mail.gmail.com> <https://groups.google.com/d/msgid/ansible-project/CAGUDtn%3DHeuyr5kyXPYODJKCvn06d6QhmMne9USsxWxD%3D8O%2B-zw%40mail.gmail.com?utm_medium=email&utm_source=footer <https://groups.google.com/d/msgid/ansible-project/CAGUDtn%3DHeuyr5kyXPYODJKCvn06d6QhmMne9USsxWxD%3D8O%2B-zw%40mail.gmail.com?utm_medium=email&utm_source=footer>>.-- Automation expert - Ansible and friendsLinux administrator & Debian maintainer Perl Dancer & conference hopper-- 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 ansible-project+unsubscr...@googlegroups.com <mailto:ansible-project%2bunsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/04e71d13-c95f-fc60-14d6-9ff8e9d21c7b%40linuxia.de <https://groups.google.com/d/msgid/ansible-project/04e71d13-c95f-fc60-14d6-9ff8e9d21c7b%40linuxia.de>. -- 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 ansible-project+unsubscr...@googlegroups.com <mailto:ansible-project+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGUDtn%3Dm5-fbF50Pjhd4tMNXe2CVqrbU6Zi6SDhkG%3DOOHa1GzA%40mail.gmail.com <https://groups.google.com/d/msgid/ansible-project/CAGUDtn%3Dm5-fbF50Pjhd4tMNXe2CVqrbU6Zi6SDhkG%3DOOHa1GzA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
-- Automation expert - Ansible and friends Linux administrator & Debian maintainer Perl Dancer & conference hopper -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/05dbebef-7ade-4603-60aa-9f7d3d6c4cac%40linuxia.de.
OpenPGP_signature
Description: OpenPGP digital signature