Saturday, August 12, 2023

Ansible Unit Test Molecule Invert Failure into Success

 This is the use case where you are expecting a task to fail during the unit test.  There are cases where you would want to test for this.  Use your imagination. 


Anyways add this to the end of your molecule/*/converge.yml file:

---
- name: Converge
  hosts: all
  vars:

    ... omitted ...

    task_that_should_fail: 'Check if web server returns 200 on localhost'
  tasks:

    ... omitted ...

    - name: Role Should Fail In This Test
      block:
        - name: Include my_role
          ansible.builtin.include_role:
            name: "my_role"
          ignore_errors: true

        - name: Passed is Fail
          fail:
            msg: "Role my_role unexpectedly successed!"

      rescue:
        - name: Failed is Pass
          debug:
            msg: "Role my_role failed when it should have!"
          when:
            - ansible_failed_task.name == task_that_should_fail

        - name: Passed is Fail
          fail:
            msg: "Role my_role unexpectedly succeed!"
          when:
            - not ansible_failed_task.name == task_that_should_fail

Wednesday, August 02, 2023

How to Add the Current Time to the Results of Your MySQL Select Statements

 MariaDB [xx_config]> select *, NOW() from servers where id = 'Fakeuuid-kinda'; 
| ID              |  VERSION |  NOW()    
| Thing One | Thing Two  | 2023-08-03 02:57:44 

Tuesday, August 01, 2023

What Data Directory is MariaDB 10.6 using?

 Run this SQL query ...

root@xoubdmz1:~ # mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 587
Server version: 10.6.14-MariaDB-1:10.6.14+maria~ubu2204-log mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'datadir';
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.001 sec)

MariaDB [(none)]>