Iterate through user input data

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?

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.

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.