All Projects → eslam-gomaa → mysql_secure_installation_Ansible

eslam-gomaa / mysql_secure_installation_Ansible

Licence: other
Idempotent Ansible Module that provides the functions of "mysql_secure_installation" script

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to mysql secure installation Ansible

hal stm32
No description or website provided.
Stars: ✭ 56 (+64.71%)
Mutual labels:  module
SelectTransform
This project is based upon https://github.com/SelectTransform/st.js but differs in implementation, functionality and robustness.
Stars: ✭ 17 (-50%)
Mutual labels:  module
terraform-aws-fargate
Terraform module to provision a Fargate-ready AWS infrastructure 🚀
Stars: ✭ 77 (+126.47%)
Mutual labels:  module
ark.db
Small and fast JSON database for Node and browser. 😋
Stars: ✭ 65 (+91.18%)
Mutual labels:  module
nuxt-brotli
Nuxt.js module which compresses assets with Brotli compression algorithm using `iltorb` library for serving it with `ngx_brotli`
Stars: ✭ 19 (-44.12%)
Mutual labels:  module
puppetlabs-java ks
Uses a combination of keytool and openssl to manage entries in a Java keystore
Stars: ✭ 34 (+0%)
Mutual labels:  module
mac-setup-playbooks
Ansible playbooks for setting up mac
Stars: ✭ 32 (-5.88%)
Mutual labels:  playbook
automated-testing-playbook
A set of principles, practices, idioms, and strategies pertaining to automated software testing and its adoption
Stars: ✭ 50 (+47.06%)
Mutual labels:  playbook
googletranslate
Python Google Translate (using reverse-engineered public API, so free)
Stars: ✭ 67 (+97.06%)
Mutual labels:  module
terraform-aws-ecr
This terraform module is used to create ECR on AWS.
Stars: ✭ 20 (-41.18%)
Mutual labels:  module
WebinoImageThumb
✂️ Webino™ Image thumbnailer for Zend Framework [LTS] http://webino.github.io/WebinoImageThumb
Stars: ✭ 40 (+17.65%)
Mutual labels:  module
ui patterns
[NOTE] Development has moved to https://drupal.org/project/ui_patterns
Stars: ✭ 87 (+155.88%)
Mutual labels:  module
nativelib-cli
NativeLib is a plugin management system for Godot engine.
Stars: ✭ 19 (-44.12%)
Mutual labels:  module
react-watermark-module
React水印组件,支持图片水印,文字水印。
Stars: ✭ 31 (-8.82%)
Mutual labels:  module
ansible-war-deploy
A playbook to deploy a WAR on Tomcat & restart it.
Stars: ✭ 20 (-41.18%)
Mutual labels:  playbook
Thread
type safe multi-threading made easier
Stars: ✭ 34 (+0%)
Mutual labels:  module
cohesity-powershell-module
This repository provides a PowerShell Module for Cohesity DataPlatform. https://cohesity.github.io/cohesity-powershell-module
Stars: ✭ 39 (+14.71%)
Mutual labels:  module
puppetlabs-gce compute
native types for managing google compute instances
Stars: ✭ 16 (-52.94%)
Mutual labels:  module
mastible
An Ansible playbook to install Mastodon
Stars: ✭ 17 (-50%)
Mutual labels:  playbook
laravel-admin
Laravel Admin panel with theme , modules ,artisan commands and helper classess.Laravel admin boilerplate with theme and modules
Stars: ✭ 22 (-35.29%)
Mutual labels:  module

mysql_secure_installation_Ansible



Wait a second !

This module has been refactored to get rid of the dependencies issue across distributions, And it's much simpler now.

Updates

  • use pymysql lib instead of MySQLdb 👎
  • Enable authentication with unix_socket
  • Add an option to disable unix_socket
  • make the output more understandable
  • run different commands based on different MySQL versions (Due to changes in newer MySQL versions)

To do,

  • Update the module doc
  • Test with more distributions
  • Validate that disable_unix_socket works well in MySQl version >= 1.4

Features

An Idempotent Ansible Module that provides the functions of mysql_secure_installation

  • Change MySQL Root Password - for a list of hosts i.e localhost, 127.0.0.1, ::1, .etc.
  • Remove Anonymous User
  • Disallow Root Login Remotely
  • Remove Test Database
  • disable unix_socket

💎 The Module is Idempotent Means that when you run it again, will not re-execute the commands If the desired state meets the current state


Dependencies

This is NOT something to worry about, It is something to make sure it's meet if you faced an error

  1. mysqladmin command (already installed with MySQL/Mariadb) -- Needed to get information such as unix_socket location & MySQL version
  2. python-pymysql which can be easily installed using the pkg manager e.g: apt, yum
    • The only caveat is that this package name may differ between distributions e.g: python3-pymysql or python36-pymysql (Trying to cover all the possible differences in the example provided)

Usage

💎 A full sample is provided at sample-playbook.yml which installs & secures MySQL -- Workes on the tested distributions below

# Modify the hosts
ansible-playbook sample-playbook.yml

  • To use a custom Ansible Module:
    • create a directory called library in your playbook or your role's directory
cd my_playbook_folder
# OR
# cd my_role_folder
mkdir library
cp mysql_secure_installation.py library/

  • Example - with a fresh MySQL Installation
- name: test mysql_secure_installation
  mysql_secure_installation:
    login_password: ''
    new_password: password22
    user: root
    login_host: localhost
    hosts: ['localhost', '127.0.0.1', '::1']
    change_root_password: true
    remove_anonymous_user: true
    disallow_root_login_remotely: true
    remove_test_db: true
  register: mysql_secure
  
# To see detailed output
- debug:
    var: mysql_secure
  • Example - Change an existing root password
- name: test mysql_secure_installation
  mysql_secure_installation:
    login_password: password22
    new_password: password23
    user: root
    login_host: localhost
    hosts: ['localhost', '127.0.0.1', '::1']

Test

Below, is a list of the tested distributions

📌 The tests are done by an automated Jenkins pipeline

Distribution Test result Comment
Centos 7
Centos 8
fedora-34
Debian 10
Debian 11
Ubuntu 16.04 Make sure you're not using an old version (Related to example syntax)
Ubuntu 18.04
Ubuntu 20.04

💎 I'll be more than happy when you let me know if you faced an error !



Updates / News

as of Mariadb v10.4+ we can not use update mysql.user > Currently that affects disable_unix_socket option for Mariadb versions above 10.4 (need some investigation & will update the module)

Error produced

ERROR 1356 (HY000): View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them



Input

:Param :Description :Default :Type
login_password Root's password to login to MySQL String
new_password New desired Root password String
user MySQL user root String
login_host host to connect to localhost String
hosts List of hosts for the provided user i.e ['localhost', '127.0.0.1', '::1'], Note: all will have the same new password [‘localhost’] List
change_root_password True Boolean
remove_anonymous_user True Boolean
disallow_root_login_remotely False Boolean
remove_test_db True Boolean
disable_unix_socket Disable login with unix_socket False Boolean

Debug Output

  • Note: The Module throws a Warning instead of an Error if the both the login_password & new_password are incorrect

Sample output

image

image



Known issues

No package matching 'python*-pymysql' is available

If you face this, don't worry it's NOT an issue, the problem is that python-pymysql might has a different name on the distro you're using

You'll probably face this if you are using a non tested distribution

image

Fix

Just Update pymysql package name with the correct name in the playbook

image

Extra mile

It is much appreciated ♥️ if you share package name on your tested distribution either with opening an issue or a pull request.


Read the Module’s Documentation

cd playbook_directory
# OR
cd role_directory
ansible-doc -M library mysql_secure_installation -v


Please leave a if you found it useful


Thank you

Maintainer: Eslam Gomaa

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].