1) This is the second message you have sent to this list asking for help with using Ansible when that's not what this list is for, after I (and perhaps others) emailed you privately and politely pointed out you were on the wrong list and pointed you at the correct forums for Ansible usage questions. Please respect the members of this list and do not continue to seek Ansible usage help here.

2) The previous answer you were given is not correct. Please see https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_environment.html.

On 10/10/23 10:51, Y.G Kumar wrote:
I am trying this:
---
---
- hosts: localhost
  vars:
    script_var1: "hi"
    script_var2: "there"
  tasks:
    - name: List
      shell: bash test.sh

cat test.sh
--
#!/bin/bash

echo "$script_var1"
echo "$script_var2"
--
But it is not working. The ansible is not picking up the variable values. stdout is empty:
--
    "stdout": "",
    "stdout_lines": []
--

On Tuesday, October 10, 2023 at 5:08:22 PM UTC+5:30 avinash...@gmail.com wrote:

    You can try

    Yaml


    - name: Execute the script with variables
      ansible.builtin.command: bash /tmp/test.sh
      vars:
        script_var1: "{{ ansible_var1 }}"
        script_var2: "{{ ansible_var2 }}"


    Shell script
    #!/bin/bash

    echo "Script variable 1: $script_var1"
    echo "Script variable 2: $script_var2"





    On Tue, 10 Oct, 2023, 17:03 Y.G Kumar, <ygku...@gmail.com> wrote:

        Hi All,

        I want to refer user defined ansible variables inside a shell
        script.  Can anyone help me how to  accomplish this ? For
        example, for the below code:

        --
            - name: Execute the script
              ansible.builtin.command: bash /tmp/test.sh
--
        I want to access ansible variables inside the shell script
        test.sh.

        Please help me.

        Thanks
        Y.G

-- You received this message because you are subscribed to the
        Google Groups "Ansible Development" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to ansible-deve...@googlegroups.com.
        To view this discussion on the web visit
        
https://groups.google.com/d/msgid/ansible-devel/aa181867-4219-4471-bea1-b809a7c1be6fn%40googlegroups.com
        
<https://groups.google.com/d/msgid/ansible-devel/aa181867-4219-4471-bea1-b809a7c1be6fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/4a516b60-a900-49cf-8f5a-10e5547ce5bfn%40googlegroups.com <https://groups.google.com/d/msgid/ansible-devel/4a516b60-a900-49cf-8f5a-10e5547ce5bfn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Ansible 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/4b85ecae-96da-4f46-804c-b96914528f0f%40kamens.us.

Reply via email to