I currently have a playbook (not completed) that installs some packages and sets up MySQL. I have one task that notifies several handlers if that task is changed. However, one of the handler tasks, which uses the ‘expect’ module, fails. The task first installs mysqld if necessary. If it installs it, it notifies six different handlers to run. One of them is " - Secure MySQL Installation". This specific task handler is the one that requires the ‘expect’ module because it prompts you for a series of questions to secure MySQL.
Here is where it gets tricky. One of the questions always fails when I answer yes. The question is: “Remove test database and access to it?” When the expect module sees this, I have it responding with a “y” for yes. It then continues to the last question and answers that one as well. The issue is that the “Remove test database and access to it?” question always throws the following error because the “test” database doesn’t exist:
Dropping test database… ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist … Failed! Not critical, keep moving…
- Removing privileges on test database… … Success!
However, the second part of that same question succeeds, which is “removing privileges on test database”
If I run it manually outside of Ansible, the result is the same. So, how do I handle this error so that the next task handler in my playbook continues even though this one failed or it thinks it failed? I want to know of my failure but I also want it to continue without halting the playbook. I have tried adding the following:
register: result failed_when: "'Can't drop database' in result.stdout" #failed_when: "'Can't drop database' in result.stderr"
However, that fails with the following error when the playbook runs:
RUNNING HANDLER [Secure MySQL Installation] ************************************ fatal: [subdomain.test.com]: FAILED! => {“failed”: true, “msg”: “The conditional check ‘‘Can’t drop database’ in result.stdout’ failed. The error was: template error while templating string: expected token ‘end of statement block’, got ‘t’. String: {% if ‘Can’t drop database’ in result.stdout %} True {% else %} False {% endif %}”}
What am I doing wrong here?
This is a copy of my playbook:
`