Pass user inputs to bash script via ansible

Hi All,

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

Regards,
Abhi

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

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

Regards,
Abhi

Hi,

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

Alex

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

Walter

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

Regards,
Abhijit

Hi Abhi,

I used
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html

for a VPN script, I use.

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

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

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