1
0
Fork 0
mirror of https://github.com/ansible-collections/community.mysql.git synced 2026-02-03 23:01:49 +00:00

Add session_vars to mysql_query. (#729)

This commit adds a `session_vars` dict to the `mysql_query` plugin,
similar to that done in #489. While this could also be done by using a
list of queries, having a dictionary allows for a cleaner query,
reusability (via merge key), and a more consistent experience when using
different plugins (like `mysql_user`, which supports `session_vars`).
This commit is contained in:
Richard Burnison 2025-09-12 03:05:30 -04:00 committed by GitHub
parent 1f9b1a29dd
commit 2e0c44f616
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 0 deletions

View file

@ -7,3 +7,5 @@
- import_tasks: mysql_query_initial.yml
- include_tasks: issue-28.yml
- include_tasks: session_vars.yml

View file

@ -0,0 +1,29 @@
---
- vars:
mysql_parameters: &mysql_params
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: '{{ mysql_host }}'
login_port: '{{ mysql_primary_port }}'
block:
- name: Select sql_log_bin without session vars
mysql_query:
<<: *mysql_params
query: SELECT @@session.sql_log_bin AS sql_log_bin
register: result_without_vars
- name: Select sql_log_bin with session vars
mysql_query:
<<: *mysql_params
query: SELECT @@session.sql_log_bin AS sql_log_bin
session_vars:
sql_log_bin: 0
register: result_with_vars
- name: Assert sql_log_bin is set
ansible.builtin.assert:
that:
- 'result_without_vars.query_result[0][0].sql_log_bin == 1'
- 'result_with_vars.query_result[0][0].sql_log_bin == 0'