# Pass user inputs to bash script via ansible

**URL:** <https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627>\
**Category:** Ansible Project\
**Created:** [February 6, 2023, 6:35pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627 "2023-02-06T18:35:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhiroxxx](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@Abhiroxxx](https://forum.ansible.com/u/Abhiroxxx)\
**Post date:** [February 6, 2023, 6:35pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/1 "2023-02-06T18:35:43Z")

</div>

Hi All,

Is there way to pass user inputs to bash script via ansible?

Regards,  
Abhi

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [February 6, 2023, 6:41pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/2 "2023-02-06T18:41:54Z")

</div>

Hi,

One possible way would be using “vars\_prompt” to request the user’s input and then pass that variable on as a parameter to your script in a “shell/command” task.

Alex

---

<div class="post-metadata">

**Author:** ![Abhiroxxx](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@Abhiroxxx](https://forum.ansible.com/u/Abhiroxxx)\
**Post date:** [February 6, 2023, 6:51pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/3 "2023-02-06T18:51:01Z")

</div>

Bash script itself asking some questions. So how can we pass that answer via ansible?

Regards,  
Abhi

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [February 6, 2023, 7:21pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/4 "2023-02-06T19:21:16Z")

</div>

Hi,

Take a look at Ansible’s “expect” module.  
It may give what you need…

Alex

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [February 6, 2023, 7:33pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/5 "2023-02-06T19:33:31Z")

</div>

How is the ansible playbook being run? command line? ansible automation platform?

Walter

---

<div class="post-metadata">

**Author:** ![Abhiroxxx](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@Abhiroxxx](https://forum.ansible.com/u/Abhiroxxx)\
**Post date:** [February 7, 2023, 7:56am UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/6 "2023-02-07T07:56:25Z")

</div>

We are executing via jenkins and it will call ansible tower to run playbook…

Regards,  
Abhijit

---

<div class="post-metadata">

**Author:** ![lee](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lee/32/4857_2.png) [@lee](https://forum.ansible.com/u/lee)\
**Post date:** [February 7, 2023, 8:54am UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/7 "2023-02-07T08:54:04Z")

</div>

Hi Abhi,

I used  
[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html)

for a VPN script, I use.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [February 7, 2023, 12:49pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/8 "2023-02-07T12:49:28Z")

</div>

Since you are submitting the job via Jenkins and web services you can use a survey on the ansible tower workflow to define variables. The web services call can supply their values. Ansible Tower will provide these variables to your playbook(s) as extra\_vars. Read the ansible tower api docs to see how they pass JSON into the API with these key:value pairs of variables and their values.

Walter

---

<div class="post-metadata">

**Author:** ![Abhiroxxx](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@Abhiroxxx](https://forum.ansible.com/u/Abhiroxxx)\
**Post date:** [February 7, 2023, 5:42pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/9 "2023-02-07T17:42:47Z")

</div>

But how can we pass this values to bash script on remote server?

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [February 7, 2023, 6:17pm UTC](https://forum.ansible.com/t/pass-user-inputs-to-bash-script-via-ansible/37627/10 "2023-02-07T18:17:25Z")

</div>

Your ansible playbook can run the shell command and pass these vars as values on the command line.

- shell: “my\_script {{ jenkins\_var1 }} {{ jenkins\_var2 }} {{ jenkins\_var3 }}”

As I said they come into the playbook as ansible extra\_vars. If your survey accepts values for these three vars and your Jenkins web services call provides them with values in JSON format “{ ‘jenkins\_var1’: ‘val1’, ‘jenkins\_var2’: ‘val2’, ‘jenkins\_var3’: 'val3 }” then it all glues together. Read the documentation and learn the modules and ansible syntax.

Walter
