Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ansible の基本 + MySQL レプリケーションを設定する事例
Search
Ian Lewis
June 10, 2014
Technology
4
6.9k
Ansible の基本 + MySQL レプリケーションを設定する事例
Ian Lewis
June 10, 2014
Tweet
Share
More Decks by Ian Lewis
See All by Ian Lewis
Kubernetes Security Best Practices
ianlewis
38
26k
The Enemy Within: Running untrusted code in Kubernetes
ianlewis
0
1.3k
The Enemy Within: Running untrusted code with gVisor
ianlewis
4
1.1k
KubeCon EU Runtime Track Recap
ianlewis
3
1.6k
コンテナによるNoOpsオートメーション
ianlewis
2
140
Google Kubernetes Engine 概要 & アップデート @ GCPUG Kansai Summit Day 2018
ianlewis
2
900
Extending Kubernetes with Custom Resources and Operator Frameworks
ianlewis
10
3.7k
Kubernetesのセキュリティのベストプラクティス
ianlewis
12
17k
Scheduling and Resource Management in Kubernetes
ianlewis
2
1.4k
Other Decks in Technology
See All in Technology
GoogleのAIエージェント論 Authors: Julia Wiesinger, Patrick Marlow and Vladimir Vuskovic
customercloud
PRO
0
200
0→1事業こそPMは営業すべし / pmconf #落選お披露目 / PM should do sales in zero to one
roki_n_
PRO
1
2.2k
「人物ごとのアルバム」の精度改善の軌跡/Improving accuracy of albums by person
mixi_engineers
PRO
2
140
Kotlin Multiplatformのポテンシャル
recruitengineers
PRO
2
160
comilioとCloudflare、そして未来へと向けて
oliver_diary
6
480
【NGK2025S】動物園(PINTO_model_zoo)に遊びに行こう
kazuhitotakahashi
0
310
大学教員が押さえておくべき生成 AI の基礎と活用例〜より効率的な教育のために〜
soh9834
1
110
2024AWSで個人的にアツかったアップデート
nagisa53
1
110
When Windows Meets Kubernetes…
pichuang
0
320
商品レコメンドでのexplicit negative feedbackの活用
alpicola
2
470
FinJAWS_reinvent2024_recap_database
asahihidehiko
2
170
AWSマルチアカウント統制環境のすゝめ / 20250115 Mitsutoshi Matsuo
shift_evolve
0
120
Featured
See All Featured
Fireside Chat
paigeccino
34
3.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Side Projects
sachag
452
42k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.2k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Become a Pro
speakerdeck
PRO
26
5.1k
Adopting Sorbet at Scale
ufuk
74
9.2k
For a Future-Friendly Web
brad_frost
176
9.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
Transcript
None
おめーだれねん?
おれは、関東人でも、 関西人でもないです。
貴様を倒すアメリカ県民だ
イアンです。
@IanMLewis
None
None
None
女性フレンドリー
連絡事項
21:30まで
Ansible とは?
An ansible is a fictional machine capable of instantaneous or
superluminal communication.
\
Ansible is an IT automation tool
自動化
None
None
pip install ansible
ansible provisioning/site.yml
Ansibleの基本
SSH NODE1 NODE2 ... Ansible 女子です
•Playbook •Inventory •Module •Role •Task •Handler 用語
Playbook
YAML
%YAML 1.2 --- YAML: YAML Ain't Markup Language What It
Is: YAML is a human friendly data serialization standard for all programming languages.
--- - hosts: dbservers sudo: True roles: - common -
mysql …
production # 本番環境のInventory stage # ステージング環境のInventory group_vars/ group1 # グループ変数
group2 # "" host_vars/ hostname1 # ホスト変数 hostname2 # "" site.yml # マスターPlaybook webservers.yml # ウェブサーバーのPlaybook dbservers.yml # DBサーバーのPlaybook
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
http://docs.ansible.com/playbooks_best_practices.html
Inventory
mail.example.com [webservers] foo.example.com bar.example.com [dbservers] one.example.com two.example.com three.example.com
SSH foo.example.com ... Ansible 女子です bar.example.com
Roles
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
Tasks
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
--- - name: Add the OS specific varibles include_vars: "{{
ansible_os_family }}.yml" - name: Install the required packages in Redhat derivatives yum: name={{ item }} state=installed with_items: ntp_pkgs when: ansible_os_family == 'RedHat' …
Modules
- name: reboot the servers command: /sbin/reboot -t now
Handlers
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
--- - name: restart ntp service: name={{ ntp_svc_name }} state=restarted
enabled=yes
まとめ
Playbook Role Task Task … Role Task … Handler Inventory
webservers dbservers
事例
MySQL
めんどくせー
https://github.com/bennojoy/ansible-roles/ tree/master/mysql
- name: Install the mysql packages in Debian derivatives apt:
name={{ item }} state=installed update_cache=yes with_items: mysql_pkgs environment: env - name: Copy the my.cnf file template: - src: my.cnf.{{ ansible_os_family }}.j2 dest: {{ mysql_conf_dir }}/my.cnf notify: - restart mysql
- name: remove the test database mysql_db: name=test state=absent -
name: Create the database's mysql_db: name={{ item.name }} state=present with_items: mysql_db when: mysql_db|lower() != 'none'
Primary
- name: Create the replication users mysql_user: - name: {{
item.name }} host: "%" password: {{ item.pass|default("foobar") }} priv: *.*:"REPLICATION SLAVE" state: present with_items: mysql_repl_user when: mysql_repl_role == 'master'
Replica
- name: Get primary servers replication status mysql_replication: mode=getmaster delegate_to:
"{{ mysql_repl_master }}" register: repl_stat when: slave|failed and mysql_repl_role == 'slave' and mysql_repl_master is defined
- name: Change the master in slave mysql_replication: - mode:
changemaster master_host: {{ mysql_repl_master }} master_log_file: {{ repl_stat.File }} master_log_pos: {{ repl_stat.Position }} master_user: {{ mysql_repl_user[0].name }} master_password: {{ mysql_repl_user[0].pass }} when: <snip>
- name: Start slave mysql_replication: mode=startslave ignore_errors: true when: mysql_repl_role
== 'slave'
またまとめ
Playbook Role Task Task … Role Task … Handler Inventory
webservers dbservers
Playbook copy my.cnf MASTER STATUS … Replica copy my.cnf …
Restart mysql Inventory primaries replicas Primary SLAVE START
ありがとう
さいごに
None
@IanMLewis http://www.ianlewis.org/ どうも!