Note
This plugin is part of the community.mysql collection (version 2.3.1).
You might already have this collection installed if you are using the ansible
package. It is not included in ansible-core
. To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.mysql
.
To use it in a playbook, specify: community.mysql.mysql_info
.
The below requirements are needed on the host that executes this module.
Parameter | Choices/Defaults | Comments |
---|---|---|
ca_cert path | The path to a Certificate Authority (CA) certificate. This option, if used, must specify the same certificate as used by the server. aliases: ssl_ca | |
check_hostname boolean added in 1.1.0 of community.mysql |
| Whether to validate the server host name when an SSL connection is required. Corresponds to MySQL CLIs --ssl switch.Setting this to false disables hostname verification. Use with caution.Requires pymysql >= 0.7.11. This option has no effect on MySQLdb. |
client_cert path | The path to a client public key certificate. aliases: ssl_cert | |
client_key path | The path to the client private key. aliases: ssl_key | |
config_file path | Default: "~/.my.cnf" | Specify a config file from which user and password are to be read. |
connect_timeout integer | Default: 30 | The connection timeout when connecting to the MySQL server. |
exclude_fields list / elements=string added in 0.1.0 of community.mysql | List of fields which are not needed to collect. Supports elements: db_size . Unsupported elements will be ignored. | |
filter list / elements=string | Limit the collected information by comma separated string or YAML list. Allowable values are version , databases , settings , global_status , users , engines , master_status , slave_status , slave_hosts .By default, collects all subsets. You can use '!' before value (for example, !settings ) to exclude it from the information.If you pass including and excluding values to the filter, for example, filter=!settings,version, the excluding values, !settings in this case, will be ignored. | |
login_db string | Database name to connect to. It makes sense if login_user is allowed to connect to a specific database only. | |
login_host string | Default: "localhost" | Host running the database. In some cases for local connections the login_unix_socket=/path/to/mysqld/socket, that is usually /var/run/mysqld/mysqld.sock , needs to be used instead of login_host=localhost. |
login_password string | The password used to authenticate with. | |
login_port integer | Default: 3306 | Port of the MySQL server. Requires login_host be defined as other than localhost if login_port is used. |
login_unix_socket string | The path to a Unix domain socket for local connections. | |
login_user string | The username used to authenticate with. | |
return_empty_dbs boolean |
| Includes names of empty databases to returned dictionary. |
Note
check_mode
.login_password
and login_user
are required when you are passing credentials. If none are present, the module will attempt to read the credentials from ~/.my.cnf
, and finally fall back to using the MySQL default login of ‘root’ with no password.Host '127.0.0.1' is not allowed to connect to this MariaDB server
.See also
The official documentation on the community.mysql.mysql_variables module.
The official documentation on the community.mysql.mysql_db module.
The official documentation on the community.mysql.mysql_user module.
The official documentation on the community.mysql.mysql_replication module.
# Display info from mysql-hosts group (using creds from ~/.my.cnf to connect): # ansible mysql-hosts -m mysql_info # Display only databases and users info: # ansible mysql-hosts -m mysql_info -a 'filter=databases,users' # Display only slave status: # ansible standby -m mysql_info -a 'filter=slave_status' # Display all info from databases group except settings: # ansible databases -m mysql_info -a 'filter=!settings' - name: Collect all possible information using passwordless root access community.mysql.mysql_info: login_user: root - name: Get MySQL version with non-default credentials community.mysql.mysql_info: login_user: mysuperuser login_password: mysuperpass filter: version - name: Collect all info except settings and users by root community.mysql.mysql_info: login_user: root login_password: rootpass filter: "!settings,!users" - name: Collect info about databases and version using ~/.my.cnf as a credential file become: yes community.mysql.mysql_info: filter: - databases - version - name: Collect info about databases and version using ~alice/.my.cnf as a credential file become: yes community.mysql.mysql_info: config_file: /home/alice/.my.cnf filter: - databases - version - name: Collect info about databases including empty and excluding their sizes become: yes community.mysql.mysql_info: config_file: /home/alice/.my.cnf filter: - databases exclude_fields: db_size return_empty_dbs: yes
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description | |
---|---|---|---|
databases dictionary | if not excluded by filter | Information about databases. Sample: [{'information_schema': {'size': 73728}, 'mysql': {'size': 656594}}] | |
size dictionary | if not excluded by filter | Database size in bytes. Sample: {'size': 656594} | |
engines dictionary | if not excluded by filter | Information about the server's storage engines. Sample: [{'CSV': {'Comment': 'CSV storage engine', 'Savepoints': 'NO', 'Support': 'YES', 'Transactions': 'NO', 'XA': 'NO'}}] | |
global_status dictionary | if not excluded by filter | Global status information. Sample: [{'Innodb_buffer_pool_read_requests': 123, 'Innodb_buffer_pool_reads': 32}] | |
master_status dictionary | if master | Master status information. Sample: [{'Binlog_Do_DB': '', 'Binlog_Ignore_DB': 'mysql', 'File': 'mysql-bin.000001', 'Position': 769}] | |
settings dictionary | if not excluded by filter | Global settings (variables) information. Sample: [{'innodb_open_files': 300, 'innodb_page_size"': 16384}] | |
slave_hosts dictionary | if master | Slave status information. Sample: [{'2': {'Host': '', 'Master_id': 1, 'Port': 3306}}] | |
slave_status dictionary | if standby | Slave status information. Sample: [{'192.168.1.101': {'3306': {'replication_user': {'Connect_Retry': 60, 'Exec_Master_Log_Pos': 769, 'Last_Errno': 0}}}}] | |
users dictionary | if not excluded by filter | Users information. Sample: [{'localhost': {'root': {'Alter_priv': 'Y', 'Alter_routine_priv': 'Y'}}}] | |
version dictionary | if not excluded by filter | Database server version. Sample: {'version': {'full': '5.5.60-MariaDB', 'major': 5, 'minor': 5, 'release': 60, 'suffix': 'MariaDB'}} | |
full string | if not excluded by filter | Full server version. Sample: 5.5.60-MariaDB | |
major integer | if not excluded by filter | Major server version. Sample: 5 | |
minor integer | if not excluded by filter | Minor server version. Sample: 5 | |
release integer | if not excluded by filter | Release server version. Sample: 60 | |
suffix string | if not excluded by filter | Server suffix, for example MySQL, MariaDB, other or none. Sample: MariaDB |
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_info_module.html