How to use ansible ‘expect’ module for multiple different responses?


Here I am trying to test my bash script where it is prompting four times.

for this script I wrote the code below, and it is working fine

But if I am doing the same for mysql_secure_installation command it not working

and its trackback is here:

I have also tried blank '' instead of "\n" for the first answer but it is not working either. I also visited Ansible expect doc but they show only very simple example and explanation. I am also trying regex match for multiple different responses but it is also not working.
Please do not recommend me to use mysql module of Ansible, because here my purpose is to learn this module for future use.


The reason is that the questions are interpreted as regexps. Hence you must escape characters with a special meaning in regular expressions, such as -()[]\?*. et cetara.


should instead be:

Good luck!

Leave a Reply