Automating DB Ops with Ansible, Chef, and Puppet
Tyler Duzan, Product Manager Percona
Automating DB Ops with Ansible, Chef, and Puppet Tyler Duzan, - - PowerPoint PPT Presentation
Automating DB Ops with Ansible, Chef, and Puppet Tyler Duzan, Product Manager Percona Who Am I? My name is Tyler Duzan Formerly an operations engineer for more than 12 years focused on security and automation Now a Product
Tyler Duzan, Product Manager Percona
2
4
5
consider automating that task
completed
6
7
8
9
10
11
13
playbooks, modules, and nodes
14
tasks:
mysql_replication: master_host: "{{ mysql_replication_master | default(master) }}" master_user: "{{ mysql_replication_user }}" master_password: "{{ mysql_replication_password }}" master_log_file: "{{ binlog_file.stdout }}" master_log_pos: "{{ binlog_position.stdout }}" mode: changemaster
mysql_replication: mode: startslave
Adapted from https://github.com/ensibel/setup-mysql-slave/blob/master/main.yml
To execute the playbook, assuming you have defined mysql_replication_user and mysql_replication_password in your host_vars file you can run just the following: ansible-playbook main.yml -e 'master=master.example.com slave=slave.example.com'
15
remote_user: root tasks:
mysql_user: user=example password=12345 priv=*.*:ALL state=present
mysql_user: user=example2 state=absent Adapted from official Ansible examples
To execute this playbook, you can run the following: ansible-playbook -i example user.yml
16
containing recipes
Ruby gems which can be installed and managed using normal Ruby processes and tools, such as Berkshelf or Bundler
can include libraries, can depend upon Ruby gems, and also can optionally include tests
regularly to ensure that a given node matches its declared environment configuration
17
18
# Depends on `mysql` community cookbook yum_repository 'mysql57-community' do mirrorlist 'http://repo.mysql.com/yum/mysql-5.7- community/el/$releasever/$basearch/' description 'MySQL 5.7 Community Edition' enabled true gpgcheck true end Adapted from example in the documentation of the ‘mysql’ community cookbook
mysql_service 'default' do version '5.7' bind_address '0.0.0.0' port '3306' data_dir '/var/lib/mysql' initial_root_password 'Ch4ng3me' action [:create, :start] end
19
chef_gem 'mysql-grantee' # Retrieve mysql application data bag items mysql_apps = search(node['mysql']['users']['d ata_bag']) # Apply permissions ruby_block 'Configure MySQL Users' do block { mysql_apply_grants(self, mysql_apps) } action :run end
Adapted from old Chef cookbook
20
node matches the declared environment configuration
21
22
include '::mysql::server' yumrepo { 'percona': descr => 'CentOS $releasever - Percona', baseurl => 'http://repo.percona.com/centos/$relea sever/os/$basearch/', gpgkey => 'http://www.percona.com/downloads/perc
enabled => 1, gpgcheck => 1, } $override_options = { 'mysqld' => { 'data_dir' => '/var/lib/mysql', 'bind_address' => '0.0.0.0', 'port' => '3306' } } Adapted from official MySQL Puppet module
23
class { '::mysql::server': package_name => 'Percona-Server-server-57', package_ensure => '5.7.23-23.1.el7', service_name => 'mysql', config_file => '/etc/my.cnf', root_password => 'Ch4ng3me', remove_default_accounts => true,
=> $override_options }
24
variables, and attributes.
25
# AWS provider provider "aws" { region = "us-west-2" } data "aws_db_instance" "database" { db_instance_identifier = "my- test-database" } resource "aws_rds_cluster" "default" { cluster_identifier = "my-test- aurora" engine = "aurora-mysql" availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] database_name = "testdb" master_username = "testuser" master_password = "Ch4ng3me" backup_retention_period = 5 preferred_backup_window = "07:00- 09:00" }
27
deploying test systems
VMs
28
name: vagrant provisioner: name: chef_zero platforms:
suites:
run_list:
run_list:
Adapted from the Kitchen CI Website Example
29
improvements called InSpec that is to migrate to if you choose.
30
require 'spec_helper' %w(user_deleted1 user_deleted2 app_one_rw1 app_one_su1).each do |user| describe command("mysql -u root -e \"select * from mysql.user where User like '#{user}'\"") do its(:stdout) { should eq('') } its(:exit_status) { should eq(0) } end end describe file('/etc/my.cnf.d') do it { should be_directory } it { should be_owned_by('root') } it { should be_grouped_into('root') } it { should be_mode('755') } end
32
33