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
Snowflake Summit 2025全体振り返り / Snowflake Summit 2025 Overall Review
mtpooh
2
380
Clineを含めたAIエージェントを 大規模組織に導入し、投資対効果を考える / Introducing AI agents into your organization
i35_267
4
1.5k
Claude Code Actionを使ったコード品質改善の取り組み
potix2
PRO
6
2k
Node-RED × MCP 勉強会 vol.1
1ftseabass
PRO
0
130
Welcome to the LLM Club
koic
0
150
OAuth/OpenID Connectで実現するMCPのセキュアなアクセス管理
kuralab
5
960
成立するElixirの再束縛(再代入)可という選択
kubell_hr
0
1k
Witchcraft for Memory
pocke
1
170
Кто отправит outbox? Валентин Удальцов, автор канала Пых
lamodatech
0
320
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
29
9.7k
20250625 Snowflake Summit 2025活用事例 レポート / Nowcast Snowflake Summit 2025 Case Study Report
kkuv
1
280
解析の定理証明実践@Lean 4
dec9ue
0
160
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
299
21k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
Automating Front-end Workflow
addyosmani
1370
200k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Become a Pro
speakerdeck
PRO
28
5.4k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
The World Runs on Bad Software
bkeepers
PRO
69
11k
Adopting Sorbet at Scale
ufuk
77
9.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
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/ どうも!