Date post: | 20-Aug-2015 |
Category: |
Technology |
Upload: | ben-mildren |
View: | 959 times |
Download: | 4 times |
MANAGING MYSQLWITH ANSIBLE
Ben Mildren04/11/14
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
What will we be covering today?
1 What?What is Ansible?
2 How?Usage andconcepts
3 Demo!PracticalExamples
3
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?
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
Why did we choose Ansible?
• Simple, Readable• Declaritive, Idempotent• Uses SSH• Agentless
6
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
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
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
Inventory File
• INI format– Hosts / Groups
– Groups of Groups
– Host and Group variables
10
Inventory File
• Example:[fra_cluster]mysql01mysql02
[deu_cluster]mysql03mysql04
[euro_clusters:children]fra_clusterdeu_cluster
11
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
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
Working with MySQL
• MySQL Specific Modules– mysql_db– mysql_user– mysql_replication– mysql_variables
14
Working with MySQL
• Other useful modules– package manager (yum / apt)– service– file– template
15
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/
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
Enter the playbook!
• conditionals• loops• async / poll• tags• error handling
18
Facts
• setup • will also run ohai and/or facter if installed• can be disabled for performance if not
required• set_fact module
19
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
Role play
• Include files• Directory Structure• Dependencies & Defaults• ansible-galaxy
– init– install, list, info, remove
21
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
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
Performance
• Connectivity– fireball (deprecated)– accelerated mode– pipelining
• forking• ansible-pull?
24
How can ansible help with MySQL?
• Installation / Upgrades• Managing configuration (mysql & host)• User Administration• Managing cronjobs• Deployments• Provisioning new nodes in a cluster
25
Demo & Questions
• Pray to the demo gods....• Questions?
26