Reputation: 61
I want to run a shell script using ansible but the shell script requires user input to execute successfully,
For example: my shell script asking the unique id for an ossec agent
, through ansible I can able to predefined my unique id (user input
).
Upvotes: 5
Views: 9187
Reputation: 151
You need to use EXPECT module: https://docs.ansible.com/ansible/latest/modules/expect_module.html
- name: Case insensitive unique id string match
expect:
command: ./myscript.sh
responses:
"Please enter your uniqueid": "myID"
# Your input in myscript.sh
no_log: true
Requirements
The below requirements are needed on the host that executes this module.
python >= 2.6
pexpect >= 3.3
Upvotes: 5
Reputation: 27005
This could help you as a starting point:
- hosts: localhost
connection: local
vars_prompt:
- name: your_name
prompt: "Enter your name"
private: no
tasks:
- name: print name
assert: that="your_name.strip()"
args:
msg: "The your_name argument shouldn't be empty!"
- debug:
var: your_name
Check more about prompts
, vars_prompt
here: https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html
Upvotes: 0