+ All Categories
Home > Technology > Managing MySQL with Ansible

Managing MySQL with Ansible

Date post: 20-Aug-2015
Category:
Upload: ben-mildren
View: 959 times
Download: 4 times
Share this document with a friend
26
MANAGING MYSQL WITH ANSIBLE Ben Mildren 04/11/14
Transcript
Page 1: Managing MySQL with Ansible

MANAGING MYSQLWITH ANSIBLE

Ben Mildren04/11/14

Page 2: Managing MySQL with Ansible

About me – Ben Mildren

• rDBA Technical Lead, Percona– Percona Managed Services

• Around 15 years RDBMS experience

• Previous roles include:– Team Technical Lead, Pythian

– Senior Database Administrator, Nokia

Email: [email protected] LinkedIn: benmildren Twitter: @productiondba Slideshare: benmildren

2

Page 3: Managing MySQL with Ansible

What will we be covering today?

1 What?What is Ansible?

2 How?Usage andconcepts

3 Demo!PracticalExamples

3

Page 4: Managing MySQL with Ansible

What problem are we looking to solve?

www.ansible.com/blog/2013/11/29/ansibles-architecture-beyond-configuration-management

4

Provisioning?

Configuration Management?

Application Deployment?

Orchestration?Automation?

Page 5: Managing MySQL with Ansible

Software solutions

• Puppet: Apache license, www.puppetlabs.com– Ruby, Manifests (Puppet language)

• Chef: Apache license, www.getchef.com– Ruby/Erlang, Cookbooks (Ruby)

• Salt: Apache license, www.saltstack.com– Python, States (YAML/Jinja2 (default renderer))

• Ansible: GPL v3 license, www.ansible.com– Python, Playbooks (YAML/Jinja2)

5

http://en.wikipedia.org/wiki/Comparison_of_open-source_configuration_management_software

Page 6: Managing MySQL with Ansible

Why did we choose Ansible?

• Simple, Readable• Declaritive, Idempotent• Uses SSH• Agentless

6

Page 7: Managing MySQL with Ansible

Installation Requirements

• Python 2.X– 2.6+ Control Machine

● Required dependencies including; PyYAML, Jinja2, pycrypto, paramiko.

– 2.4+ Managed Node● python-simplejson (if 2.5 or below)● libselinux-python (if selinux enabled)

(and using copy/file/template functions)

7

http://docs.ansible.com/intro_installation.html

Page 8: Managing MySQL with Ansible

Installation

• Package Manager– yum (via epel)

– apt

• pip• Source (https://github.com/ansible/ansible)

https://github.com/ansible/ansible/blob/devel/CHANGELOG.md

8

http://docs.ansible.com/intro_installation.html

Page 9: Managing MySQL with Ansible

Configuration

• Config fileANSIBLE_CONFIG > ./ansible.cfg >

~/.ansible.cfg > /etc/ansible/ansible.cfg

(settings are not merged)

• Inventory file– /etc/ansible/hosts (default)

– or can use dynamic inventory scripthttps://github.com/ansible/ansible/tree/devel/plugins/inventory

9

Page 10: Managing MySQL with Ansible

Inventory File

• INI format– Hosts / Groups

– Groups of Groups

– Host and Group variables

10

Page 11: Managing MySQL with Ansible

Inventory File

• Example:[fra_cluster]mysql01mysql02

[deu_cluster]mysql03mysql04

[euro_clusters:children]fra_clusterdeu_cluster

11

Page 12: Managing MySQL with Ansible

Ad-Hoc Commands

• ansible <host-pattern> [options]

<host-pattern> → inventory file

/etc/ansible/hosts (default)

-i PATH, --inventory=PATH

[options]

typically module (-m) & arguments (-a)

also connectivity, logging, etc

12

Page 13: Managing MySQL with Ansible

Modules

• ad-hoc default == command module• ansible-doc

-l, --list

-s, --snippet [module]

[module]

• can develop custom modules– Potentially any language, JSON output

13

http://docs.ansible.com/modules_by_category.html

Page 14: Managing MySQL with Ansible

Working with MySQL

• MySQL Specific Modules– mysql_db– mysql_user– mysql_replication– mysql_variables

14

Page 15: Managing MySQL with Ansible

Working with MySQL

• Other useful modules– package manager (yum / apt)– service– file– template

15

Page 16: Managing MySQL with Ansible

Templates

• jinja2 formatted– variables, conditionals, loops, etc..

[mysqld]

### General options

user = mysql

pid-file = {{ mysql_run_dir }}/mysqld.pid

socket = {{ mysql_run_dir }}/mysqld.sock

datadir = {{ mysql_data_dir }}

tmpdir = {{ mysql_tmp_dir }}

16

http://jinja.pocoo.org/docs/dev/templates/

Page 17: Managing MySQL with Ansible

Enter the playbook!

• Written in YAML• Consists of one or more “plays”

– Target section– Variable section– Task section– Handlers section

• Executed using ansible-playbook

17

Page 18: Managing MySQL with Ansible

Enter the playbook!

• conditionals• loops• async / poll• tags• error handling

18

Page 19: Managing MySQL with Ansible

Facts

• setup • will also run ohai and/or facter if installed• can be disabled for performance if not

required• set_fact module

19

Page 20: Managing MySQL with Ansible

Running playbooks

• ansible-playbook playbook.yml– similar connectivity options to ad-hoc ansible

command

– Has additional options specific to running playbooks, e.g:

--list-hosts, --list-tasks

--syntax-check, --check (-C), --diff (-D)

--step, --start-at-task

--tags (-t), --skip-tags

20

Page 21: Managing MySQL with Ansible

Role play

• Include files• Directory Structure• Dependencies & Defaults• ansible-galaxy

– init– install, list, info, remove

21

Page 22: Managing MySQL with Ansible

Logging

• cowsay or nocows=1• verbose & verboser• ansible log• callback plugins

– Notification (email, campfire, hipchat, etc)

– improved logging (ELK anybody?)

22

https://github.com/ansible/ansible/tree/devel/plugins/callbacks

Page 23: Managing MySQL with Ansible

Password Management

• lookup passwords• ansible-vault

– create/edit/encrypt/decrypt/rekey

– aes256 encryption

ansible-playbook --ask-vault-pass

ansible-playbook --vault-password-file

(file or script)

23

Page 24: Managing MySQL with Ansible

Performance

• Connectivity– fireball (deprecated)– accelerated mode– pipelining

• forking• ansible-pull?

24

Page 25: Managing MySQL with Ansible

How can ansible help with MySQL?

• Installation / Upgrades• Managing configuration (mysql & host)• User Administration• Managing cronjobs• Deployments• Provisioning new nodes in a cluster

25

Page 26: Managing MySQL with Ansible

Demo & Questions

• Pray to the demo gods....• Questions?

26


Recommended