add mysql role
This commit is contained in:
parent
523d6f3b32
commit
3e982b9729
38
roles/mysql/README.md
Normal file
38
roles/mysql/README.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Role Name
|
||||||
|
=========
|
||||||
|
|
||||||
|
A brief description of the role goes here.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||||
|
|
||||||
|
- hosts: servers
|
||||||
|
roles:
|
||||||
|
- { role: username.rolename, x: 42 }
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
57
roles/mysql/defaults/main.yaml
Normal file
57
roles/mysql/defaults/main.yaml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
mysql_package_state: 'present'
|
||||||
|
|
||||||
|
mysql_service_name: 'mysql'
|
||||||
|
mysql_service_state: 'started'
|
||||||
|
mysql_service_enabled: yes
|
||||||
|
|
||||||
|
mysql_initialize_log_error: /var/tmp/mysqld_initialize.log
|
||||||
|
|
||||||
|
mysql_cfg_path: /etc/my.cnf
|
||||||
|
|
||||||
|
mysql_datadir_owner: mysql
|
||||||
|
mysql_datadir_group: mysql
|
||||||
|
mysql_datadir_mode: 0700
|
||||||
|
|
||||||
|
mysql_config:
|
||||||
|
mysql:
|
||||||
|
port: 3306
|
||||||
|
socket: /var/run/mysqld/mysqld.sock
|
||||||
|
mysqld:
|
||||||
|
basedir: /usr
|
||||||
|
bind_address: 127.0.0.1
|
||||||
|
datadir: /var/lib/mysql
|
||||||
|
default_storage_engine: InnoDB
|
||||||
|
innodb_buffer_pool_size: "{{ (ansible_memtotal_mb * 0.25) | int }}M"
|
||||||
|
innodb_file_per_table: 1
|
||||||
|
innodb_flush_log_at_trx_commit: 1
|
||||||
|
innodb_flush_method: O_DIRECT
|
||||||
|
innodb_log_file_size: 128M
|
||||||
|
innodb_log_files_in_group: 2
|
||||||
|
key_buffer_size: 16M
|
||||||
|
log_error: /var/log/mysql/mysql-error.log
|
||||||
|
log_queries_not_using_indexes: 1
|
||||||
|
max_allowed_packet: 16M
|
||||||
|
max_connect_errors: 1000000
|
||||||
|
max_connections: 100
|
||||||
|
max_heap_table_size: 32M
|
||||||
|
myisam_recover_options: FORCE,BACKUP
|
||||||
|
open_files_limit: 65535
|
||||||
|
pid_file: /var/run/mysqld/mysqld.pid
|
||||||
|
query_cache_size: 0
|
||||||
|
query_cache_type: 0
|
||||||
|
slow_query_log: 1
|
||||||
|
slow_query_log_file: /var/log/mysql/mysql-slow.log
|
||||||
|
socket: /var/run/mysqld/mysqld.sock
|
||||||
|
table_definition_cache: 4096
|
||||||
|
table_open_cache: 300
|
||||||
|
thread_cache_size: 16
|
||||||
|
tmp_table_size: 32M
|
||||||
|
tmpdir: /tmp
|
||||||
|
user: mysql
|
||||||
|
mysqld_safe:
|
||||||
|
nice: 0
|
||||||
|
socket: /var/run/mysqld/mysqld.sock
|
||||||
|
syslog: ~
|
||||||
|
|
||||||
|
# vim:ft=yaml.ansible:
|
5
roles/mysql/handlers/main.yml
Normal file
5
roles/mysql/handlers/main.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: restart mysql
|
||||||
|
service:
|
||||||
|
name: "{{ mysql_service_name }}"
|
||||||
|
state: restarted
|
60
roles/mysql/meta/main.yml
Normal file
60
roles/mysql/meta/main.yml
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
galaxy_info:
|
||||||
|
author: your name
|
||||||
|
description: your description
|
||||||
|
company: your company (optional)
|
||||||
|
|
||||||
|
# If the issue tracker for your role is not on github, uncomment the
|
||||||
|
# next line and provide a value
|
||||||
|
# issue_tracker_url: http://example.com/issue/tracker
|
||||||
|
|
||||||
|
# Some suggested licenses:
|
||||||
|
# - BSD (default)
|
||||||
|
# - MIT
|
||||||
|
# - GPLv2
|
||||||
|
# - GPLv3
|
||||||
|
# - Apache
|
||||||
|
# - CC-BY
|
||||||
|
license: license (GPLv2, CC-BY, etc)
|
||||||
|
|
||||||
|
min_ansible_version: 2.4
|
||||||
|
|
||||||
|
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||||
|
# min_ansible_container_version:
|
||||||
|
|
||||||
|
# Optionally specify the branch Galaxy will use when accessing the GitHub
|
||||||
|
# repo for this role. During role install, if no tags are available,
|
||||||
|
# Galaxy will use this branch. During import Galaxy will access files on
|
||||||
|
# this branch. If Travis integration is configured, only notifications for this
|
||||||
|
# branch will be accepted. Otherwise, in all cases, the repo's default branch
|
||||||
|
# (usually master) will be used.
|
||||||
|
#github_branch:
|
||||||
|
|
||||||
|
#
|
||||||
|
# Provide a list of supported platforms, and for each platform a list of versions.
|
||||||
|
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
|
||||||
|
# To view available platforms and versions (or releases), visit:
|
||||||
|
# https://galaxy.ansible.com/api/v1/platforms/
|
||||||
|
#
|
||||||
|
# platforms:
|
||||||
|
# - name: Fedora
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 25
|
||||||
|
# - name: SomePlatform
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 1.0
|
||||||
|
# - 7
|
||||||
|
# - 99.99
|
||||||
|
|
||||||
|
galaxy_tags: []
|
||||||
|
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||||
|
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||||
|
# remove the '[]' above, if you add tags to this list.
|
||||||
|
#
|
||||||
|
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||||
|
# Maximum 20 tags per role.
|
||||||
|
|
||||||
|
dependencies: []
|
||||||
|
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||||
|
# if you add dependencies to this list.
|
39
roles/mysql/tasks/main.yml
Normal file
39
roles/mysql/tasks/main.yml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
- name: gather OS distribution version specific variables
|
||||||
|
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
|
||||||
|
|
||||||
|
- name: gather OS distribution specific variables
|
||||||
|
include_vars: "{{ ansible_distribution }}.yaml"
|
||||||
|
|
||||||
|
- name: gather OS family specific variables
|
||||||
|
include_vars: "{{ ansible_os_family }}.yaml"
|
||||||
|
|
||||||
|
- name: manage mysql package
|
||||||
|
package:
|
||||||
|
name: "{{ mysql_package_name }}"
|
||||||
|
state: "{{ mysql_package_state }}"
|
||||||
|
|
||||||
|
- name: create datadir
|
||||||
|
file:
|
||||||
|
path: "{{ mysql_config.mysqld.datadir }}"
|
||||||
|
owner: "{{ mysql_datadir_owner }}"
|
||||||
|
group: "{{ mysql_datadir_group }}"
|
||||||
|
mode: "{{ mysql_datadir_mode }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: initialize mysql
|
||||||
|
command: "mysqld --initialize --log-error={{ mysql_initialize_log_error }}"
|
||||||
|
args:
|
||||||
|
creates: "{{ mysql_config.mysqld.datadir }}/mysql"
|
||||||
|
|
||||||
|
- name: configure mysql
|
||||||
|
template:
|
||||||
|
src: my.cnf.j2
|
||||||
|
dest: "{{ mysql_cfg_path }}"
|
||||||
|
notify: restart mysql
|
||||||
|
|
||||||
|
- name: manage mysql service
|
||||||
|
service:
|
||||||
|
name: "{{ mysql_service_name }}"
|
||||||
|
state: "{{ mysql_service_state }}"
|
||||||
|
enabled: "{{ mysql_service_enabled }}"
|
12
roles/mysql/templates/my.cnf.j2
Normal file
12
roles/mysql/templates/my.cnf.j2
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# {{ ansible_managed }}
|
||||||
|
{% for section, cfg in mysql_config.iteritems() | sort %}
|
||||||
|
|
||||||
|
[{{section}}]
|
||||||
|
{% for k, v in cfg.iteritems() | sort %}
|
||||||
|
{% if k is defined and v is not none %}
|
||||||
|
{{ k }} = {{ v }}
|
||||||
|
{% elif k and v is none %}
|
||||||
|
{{ k }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
2
roles/mysql/tests/inventory
Normal file
2
roles/mysql/tests/inventory
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
5
roles/mysql/tests/test.yml
Normal file
5
roles/mysql/tests/test.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
remote_user: root
|
||||||
|
roles:
|
||||||
|
- roles/mysql
|
2
roles/mysql/vars/Debian.yaml
Normal file
2
roles/mysql/vars/Debian.yaml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
mysql_cfg_path: /etc/my.cnf
|
5
roles/mysql/vars/Ubuntu-18.yaml
Normal file
5
roles/mysql/vars/Ubuntu-18.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
mysql_service_name: 'mysql.service'
|
||||||
|
mysql_cfg_path: /etc/mysql/my.cnf
|
||||||
|
|
||||||
|
# vim:ft=yaml.ansible:
|
4
roles/mysql/vars/Ubuntu.yaml
Normal file
4
roles/mysql/vars/Ubuntu.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
mysql_package_name: 'mysql-server'
|
||||||
|
|
||||||
|
# vim:ft=yaml.ansible:
|
2
roles/mysql/vars/main.yml
Normal file
2
roles/mysql/vars/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for roles/mysql
|
Loading…
Reference in New Issue
Block a user