Not an answer, but a thought - instead of using the shell module, have you 
thought about using the mysql_info module?

https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_info_module.html#ansible-collections-community-mysql-mysql-info-module
 
<https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_info_module.html#ansible-collections-community-mysql-mysql-info-module>

Or any other of the mySQL modules:

https://docs.ansible.com/ansible/latest/collections/community/mysql/index.html 
<https://docs.ansible.com/ansible/latest/collections/community/mysql/index.html>

> On Feb 9, 2022, at 10:51 AM, SysAdmin EM <[email protected] 
> <mailto:[email protected]>> wrote:
> 
> Hello, I am creating a playbook, in the first task I am checking if a 
> database exists which is previously created with another task.
> I need to finish the playbook if the database does not exist, for this to 
> assemble the next playbook
> 
>     - name: Check if database exists
>   shell: |
>     mysql -hhost -uuser -ppassword -e "show databases" | egrep db
>   register: mysql_exist
>   failed_when: "'FAILED' in mysql_exist.stderr"
> 
> - name:
>   debug:
>     msg: "{{ mysql_exist.stdout }}"
> 
> but the playbook keeps going and I need it to end the playbook if the 
> database doesn’t exist.
> 
> the next task called "Check Queue in RabbitMQ" should not be executed because 
> the database does not exist.
> 
> changed: [server01-stage]
> TASK [debug] 
> ***************************************************************************************************************************************
> ok: [server01-stage] => {
> "msg": ""
> }
> TASK [Check Queue in RabbitMQ] 
> ****************************************************************************************************************
> fatal: [schedule01-stage]: FAILED! => {"changed": true, "cmd": "rabbitmqadmin 
> --host=host --port=port2 --username=user --password=usert -f long list queues 
> | egrep \"AWPP\"\n", "delta": "0:00:00.389108", "end": "2022-02-09 
> 16:42:13.394477", "msg": "non-zero return code", "rc": 1, "start": 
> "2022-02-09 16:42:13.005369", "stderr": "", "stderr_lines": [], "stdout": "", 
> "stdout_lines": []}
> PLAY RECAP 
> *****************************************************************************************************************************************
> schedule01-stage : ok=2 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 
> ignored=0
> 
> any helps??
> 
> Regards,
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/CAGUDtnm3JqG4VQAPMi0RzhFOp-NUCBr5LQWLcof85VEbv03Hfg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/ansible-project/CAGUDtnm3JqG4VQAPMi0RzhFOp-NUCBr5LQWLcof85VEbv03Hfg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/67FFB01C-9707-40BF-B4E7-128A156E76A1%40gmail.com.

Reply via email to