Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community.mysql.mysql_db appears not to support relative paths when importing databases #395

Closed
chriscroome opened this issue Jun 8, 2022 · 10 comments · Fixed by #396
Closed

Comments

@chriscroome
Copy link
Contributor

The MariaDB sys schema cannot be imported using community.mysql.mysql_db, for example this Ansible:

    - name: MariaDB sys repo directory present
      ansible.builtin.file:
        path: /usr/local/src/mariadb-sys
        state: directory
        mode: 0755

    - name: MariaDB sys schema repo present
      ansible.builtin.git:
        repo: https://github.com/iwindfree/mariadb-sys.git
        dest: /usr/local/src/mariadb-sys
        clone: true 
        version: bcd090461189f35dcadfae77f87ca233a6587f95

    - name: Import the MariaDB sys schema
      community.mysql.mysql_db:
        name: all
        state: import
        target: /usr/local/src/mariadb-sys/mariadb_sys_install.sql
        login_unix_socket: /run/mysqld/mysqld.sock

Fails with:

ERROR at line 11: Failed to open file './views/v_threads.sql', error: 2

I suspect this is because relative links are used in the SQL, for example:

SOURCE ./views/v_threads.sql

The ansible.builtin.shell module can be used since is supports chdir, for example:

    - name: Import the sys schema using the shell module
      shell: mysql < ./mariadb_sys_install.sql
      args:
        chdir: /usr/local/src/mariadb-sys

Could adding support for cd'ing into to the directory that contains the file to be imported or adding a chdir option to the module be considered as a feature request to solve this problem?

@Andersson007
Copy link
Collaborator

Andersson007 commented Jun 9, 2022

@chriscroome hello again and thanks for reporting this!

Adding the new option sounds good to me (if i understand correctly, we could leverage os.path(BASE_DIR, file) for this) UPDATE: not sure about the implementation.

@bmalynovytch @rsicart @Jorge-Rodriguez @betanummeric what do you folks think? If you're OK with this, does anyone want to implement this?

@Andersson007
Copy link
Collaborator

@chriscroome i created a PR #396, could you please take a look?

@Andersson007
Copy link
Collaborator

@chriscroome the PR has been reviewed and merged, thanks for the contribution!

@chriscroome
Copy link
Contributor Author

No problem, did you consider making changing to the directory that the file to be imported resides in the default behaviour?

@Andersson007
Copy link
Collaborator

No problem, did you consider making changing to the directory that the file to be imported resides in the default behaviour?

thanks for the idea!
it would be (maybe theoretically but) a breaking change, so would be nice to hear @bmalynovytch , @Jorge-Rodriguez and @betanummeric 's opinions (Roger rsicart is away this week)

@chriscroome
Copy link
Contributor Author

I think it would only be a breaking change if a SQL dump file anticipated the default working directory and had paths relative to that wouldn't it? That seems like a fairly unlikely scenario since this varies doesn't it (please correct me if I'm wrong)?

@betanummeric
Copy link
Member

The target is not the only argument affected by chdir. I think ca_cert, client_cert, client_key and login_unix_socket could also be relative to the working directory.
The implicit chdir does not sound intuitive to me, but I don't use the module. Would there be a way to opt-out with chdir: false or something?

@chriscroome
Copy link
Contributor Author

chriscroome commented Jun 13, 2022

@betanummeric what is the default working directory?

I was working under the assumption that is isn't always the same for all connections to all servers so nobody will be using path relative to it, but perhaps I have got this wrong?

@Andersson007
Copy link
Collaborator

The target is not the only argument affected by chdir. I think ca_cert, client_cert, client_key and login_unix_socket could also be relative to the working directory. The implicit chdir does not sound intuitive to me, but I don't use the module. Would there be a way to opt-out with chdir: false or something?

@betanummeric great catch about the cert and other arguments, thanks!

@betanummeric
Copy link
Member

As far as I know the default working directory is the home of the linux user as whom ansible connects to the target system. Relative paths could be used in theory, but I cannot speak from experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants