local_action and mysql_db doesn't work together

I want to make sure that a database in mysql does exist and when using the following two actions:

  • name: “Ensure remote database”
    mysql_db: login_host=‘127.0.0.1’
    name=‘{{ migrate_db_remote }}’
    state=‘present’

  • name: “Ensure local database”
    local_action: module=mysql_db
    login_host=‘127.0.0.1’
    name=‘{{ migrate_db_remote }}’
    state=‘present’

the first one does work and the second one throws the following error:

fatal: [host] => module module=mysql_db not found in /usr/share/ansible/inventory:/usr/share/ansible/packaging:/usr/share/ansible/database:/usr/share/ansible/monitoring:/usr/share/ansible/commands:/usr/share/ansible/files:/usr/share/ansible/net_infrastructure:/usr/share/ansible/utilities:/usr/share/ansible/network:/usr/share/ansible/internal:/usr/share/ansible/source_control:/usr/share/ansible/web_infrastructure:/usr/share/ansible/system:/usr/share/ansible/messaging:/usr/share/ansible/cloud:/usr/share/ansible/notification:/usr/share/ansible

I checked, the python-mysqldb package is installed on both the local and the remote host. So I’m not sure what’s causing this issue. Any help much appreciated.

Found it. The correct notation for the local_action would be like this:

  • name: “Ensure local database”
    local_action: mysql_db
    login_host=‘127.0.0.1’
    name=‘{{ migrate_db_remote }}’
    state=‘present’

What’s changed? The “module=” is stripped out.

This is cleaner:

  • name: “Ensure local database exists”
    local_action: mysql_db login_host=127.0.0.1 name=‘{{ migrate_db_remote }}’ state=present

Don’t need the module= or a lot of the quotes.