Iterate through user input data

29 views
Skip to first unread message

Ahmed Jaad

unread,
Dec 28, 2016, 10:53:30 AM12/28/16
to Ansible Project
Im a newbie to ansible, and im trying to write an ansible script which would continuously prompt user to insert data and use the data to perform some tasks until the user decides to end the loop, a shell script serving the same purpose would look like this.

read -s -p "Create new directory? y/n: " response while [[ "$response" == "y" ]] do read -s -p "Enter the name of direcory: " name mkdir $name if [ $? -ne 0 ] then echo "Failed to create new directory $name" exit 1 fi read -s -p "Create another new directory? y/n: " response done
so how do i go about this?

Kai Stian Olstad

unread,
Dec 29, 2016, 7:35:36 AM12/29/16
to ansible...@googlegroups.com
It's not possible with Ansible, Ansible have prompts
https://docs.ansible.com/ansible/playbooks_prompts.html
But this is question you will have to ask and answer upfront before
playbook the rest of the playbook get executed.

--
Kai Stian Olstad

Brian Coca

unread,
Jan 5, 2017, 1:50:37 PM1/5/17
to ansible...@googlegroups.com
The `pause` module can prompt and use the responses for a more 'interactive' play. So for example, you can use `stat` to check if the directory exists and `pause` to ask what to do next.


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages