Pass user inputs to bash script via ansible

329 views
Skip to first unread message

Linux Study

unread,
Feb 6, 2023, 1:36:16 PM2/6/23
to ansible...@googlegroups.com
Hi All,

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


Regards,
Abhi

Alex Wanderley

unread,
Feb 6, 2023, 1:42:23 PM2/6/23
to ansible...@googlegroups.com
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

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEcjLFzU8q%2BgQgGE9QJu6WkhVWsW_6EDNh2aQ%3DVaxq%2BO1cBybw%40mail.gmail.com.


--

 

Edmonton_sig_RGB_S.jpg

Alex Wanderley

Application and Infrastructure Analyst II
Server Solutions & Automation

Financial and Corporate Services | Open City and Technology  

 

780-496-4156  Office

780-819-0273  Mobile

 

City of Edmonton

Century Place, 19th Floor

9803 102A Avenue NW

Edmonton AB, T5J 3A3

 

All information contained in this email post is proprietary to the City of Edmonton, confidential and intended only for the addressed recipient. If you have received this post in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination or distribution of this email, if misdirected, is strictly prohibited.


The contents of this message and any attachment(s) are confidential, proprietary to the City of Edmonton, and are intended only for the addressed recipient. If you have received this in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination, or distribution of this message, if misdirected, is strictly prohibited.

Linux Study

unread,
Feb 6, 2023, 1:51:35 PM2/6/23
to ansible...@googlegroups.com
Bash script itself asking some questions. So how can we pass that answer via ansible?

Regards,
Abhi

Alex Wanderley

unread,
Feb 6, 2023, 2:21:43 PM2/6/23
to ansible...@googlegroups.com
Hi,

Take a look at Ansible's "expect" module.
It may give what you need...

Alex

Rowe, Walter P. (Fed)

unread,
Feb 6, 2023, 2:33:49 PM2/6/23
to ansible...@googlegroups.com
How is the ansible playbook being run? command line? ansible automation platform?

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Linux Study

unread,
Feb 7, 2023, 2:56:54 AM2/7/23
to ansible...@googlegroups.com
We are  executing via jenkins and it will call ansible tower to run playbook...

Regards,
Abhijit

Lee Thomas Stephen

unread,
Feb 7, 2023, 3:54:56 AM2/7/23
to ansible...@googlegroups.com

--

Rowe, Walter P. (Fed)

unread,
Feb 7, 2023, 7:49:51 AM2/7/23
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Linux Study

unread,
Feb 7, 2023, 12:43:15 PM2/7/23
to ansible...@googlegroups.com
But how can we pass this values to bash script on remote server?

Rowe, Walter P. (Fed)

unread,
Feb 7, 2023, 1:17:42 PM2/7/23
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
Reply all
Reply to author
Forward
0 new messages