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
7k
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.2k
KubeCon EU Runtime Track Recap
ianlewis
3
1.6k
コンテナによるNoOpsオートメーション
ianlewis
2
160
Google Kubernetes Engine 概要 & アップデート @ GCPUG Kansai Summit Day 2018
ianlewis
2
930
Extending Kubernetes with Custom Resources and Operator Frameworks
ianlewis
10
3.8k
Kubernetesのセキュリティのベストプラクティス
ianlewis
12
17k
Scheduling and Resource Management in Kubernetes
ianlewis
2
1.4k
Other Decks in Technology
See All in Technology
Model Mondays S2E02: Model Context Protocol
nitya
0
220
Snowflake Summit 2025全体振り返り / Snowflake Summit 2025 Overall Review
mtpooh
2
390
Fabric + Databricks 2025.6 の最新情報ピックアップ
ryomaru0825
1
130
AWS テクニカルサポートとエンドカスタマーの中間地点から見えるより良いサポートの活用方法
kazzpapa3
2
500
Windows 11 で AWS Documentation MCP Server 接続実践/practical-aws-documentation-mcp-server-connection-on-windows-11
emiki
0
910
エンジニア向け技術スタック情報
kauche
1
240
MySQL5.6から8.4へ 戦いの記録
kyoshidaxx
1
180
第9回情シス転職ミートアップ_テックタッチ株式会社
forester3003
0
220
Wasm元年
askua
0
130
20250625 Snowflake Summit 2025活用事例 レポート / Nowcast Snowflake Summit 2025 Case Study Report
kkuv
1
290
5min GuardDuty Extended Threat Detection EKS
takakuni
0
110
Amazon S3標準/ S3 Tables/S3 Express One Zoneを使ったログ分析
shigeruoda
3
450
Featured
See All Featured
Writing Fast Ruby
sferik
628
61k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
790
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.3k
Code Reviewing Like a Champion
maltzj
524
40k
How STYLIGHT went responsive
nonsquared
100
5.6k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Docker and Python
trallard
44
3.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
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/ どうも!