This repository includes also a CI/CD pipline using Jenkins for building a test environment to deliver the module
Ansible module runs arbitrary MySQL queries.
The below requirements are needed on the host that executes this module.
PyMySQL
Parameter | Choices/Defaults | Comments |
---|---|---|
autocommitboolean |
Choices: false ← true |
Execute in autocommit mode when the query |
dbstring |
Name of database to connect to and run queries against | |
login_hoststring |
Default: localhost |
Host running the database should be execluded if config_file was provided |
login_passwordstring |
The password used to authenticate with should be execluded if config_file was provided |
|
login_unix_socketstring |
Default: /var/lib/mysql/mysql.sock |
Path to a Unix domain socket |
login_userstring |
The username used to authenticate with | |
named_argsdictionary |
Dictionary of key-value arguments to pass to the query | |
positional_argslist |
List of values to be passed as positional arguments to the query | |
querystring |
SQL query to run | |
fetchoneboolean |
get only the first result of select SQL query | |
config_filestring |
ini file containing client database credentials If this parameter is specified, login_user and login_password should be excluded |
- name: Select query to db acme with positional arguments
mysql_query:
db: acme
login_user: django
login_password: mysecretpass
query: SELECT * FROM acme WHERE id = %s AND story = %s
positional_args:
- 1
- test
- name: Select query to test_db with named_args
mysql_query:
db: acme
login_user: django
login_password: mysecretpass
query: SELECT * FROM test WHERE id = %(id_val)s AND story = %(story_val)s
named_args:
id_val: 1
story_val: test
- name: Insert query to test_table in db test_db
mysql_query:
db: acme
login_user: django
login_password: mysecretpass
query: INSERT INTO test_table (id, story) VALUES (2, 'my_long_story')
- name: fetch only the first result of select SQL query
mysql_query:
db: test
config_file: '/root/.my.cnf'
query: select * from test_table
fetchone: true
key | Returned | Description |
---|---|---|
querystring |
always | Query that was tried to be executed |
query_resultlist |
changed | List of dictionaries in column:value form representing returned rows |
rowcountinteger |
always | Number of affected rows. |