linuxansiblemariadbansible-awx

Invalid Syntax on community.mysql.mysql_user with Ansible AWX


I am trying to run a playbook through AWX where I want to create a mariadb user with permissions. The playbook works nicely when run from ansible on my local machine. However, when I try to run the job on AWX, I get the following error :

"module_stdout": "Traceback (most recent call last):\r\n File "/home/ansible/.ansible/tmp/ansible-tmp-1685691063.0199862-220-69171919718447/AnsiballZ_mysql_user.py", line 107, in \r\n _ansiballz_main()\r\n File "/home/ansible/.ansible/tmp/ansible-tmp-1685691063.0199862-220-69171919718447/AnsiballZ_mysql_user.py", line 99, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File "/home/ansible/.ansible/tmp/ansible-tmp-1685691063.0199862-220-69171919718447/AnsiballZ_mysql_user.py", line 48, in invoke_module\r\n run_name='main', alter_sys=True)\r\n File "/usr/lib/python3.5/runpy.py", line 205, in run_module\r\n return _run_module_code(code, init_globals, run_name, mod_spec)\r\n File "/usr/lib/python3.5/runpy.py", line 96, in _run_module_code\r\n mod_name, mod_spec, pkg_name, script_name)\r\n File "/usr/lib/python3.5/runpy.py", line 85, in _run_code\r\n exec(code, run_globals)\r\n File "/tmp/ansible_community.mysql.mysql_user_payload_r3e02o87/ansible_community.mysql.mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py", line 352, in \r\n File "", line 969, in _find_and_load\r\n File "", line 958, in _find_and_load_unlocked\r\n File "", line 664, in _load_unlocked\r\n File "", line 634, in _load_backward_compatible\r\n File "/tmp/ansible_community.mysql.mysql_user_payload_r3e02o87/ansible_community.mysql.mysql_user_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py", line 22, in \r\n File "/usr/local/lib/python3.5/dist-packages/pymysql/init.py", line 59, in \r\n from . import connections # noqa: E402\r\n File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 206\r\n ):\r\n ^\r\nSyntaxError: invalid syntax\r\n"

Here's the task for creating the user :

- name : Create mariadb user
  community.mysql.mysql_user:
    login_user: root
    login_password: "{{ root_password }}"
    name: user
    password: "{{ mariadb_user_pw }}"
    priv: "*.*:PROCESS,SELECT,CREATE,CREATE TABLESPACE,INSERT"
    state: present

Solution

  • Ensure the hosts have the correct package installed.
    Include this in your playbook:

    - name: ensure mysql package for the mysql api is installed
      pip:
        name: pymysql
        executable: pip3
    

    --

    you should check your awx container.
    either by logging in to the container itself, and check stuff manually, or you can do this w ansible as well.

    - shell: locate ansible-galaxy
      delegate_to: localhost
      register: check_galaxy
    
    - debug:
        msg: "{{ check_galaxy.stdout }}"
      delegate_to: localhost
    

    Then, once you have the output, simply check the installed roles and it versions

    - shell: ansible-galaxy collection list
      delegate_to: localhost
      register: check_collection
    
    - debug:
        msg: "{{ check_collection }}"
      delegate_to: localhost