Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dynamic Inventoryと参照変数
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
bungoume
September 22, 2014
Technology
5.1k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dynamic Inventoryと参照変数
Ansible Meetup in Tokyo 2014.09でのLT発表資料です。
http://ansible-users.connpass.com/event/7942/
bungoume
September 22, 2014
More Decks by bungoume
See All by bungoume
djangocongressjp2023_password_hash
bungoume
2
1.6k
日経電子版でのDjango活用事例紹介 / djangocongressjp2022-nikkei
bungoume
4
7.3k
CircleCIの活用事例とCI高速化/circleci-community-meetup3-speedup
bungoume
3
1.6k
Password Hashing djangocongress 20180519
bungoume
5
4.3k
OSSで始めるセキュリティログ収集/oss-securitylog-builderscon2017
bungoume
29
11k
日経電子版のアプリ開発を支えるログ活用術/nikkei-log-201609
bungoume
1
1.4k
Kibanaで秒間1万件のアクセスを可視化した話/nikkei-kibana-loganalyst2015
bungoume
20
17k
uwsgi-docker-pycon2015
bungoume
10
61k
Ansibleを結構使ってみた/ansible-nikkei-2015
bungoume
32
15k
Other Decks in Technology
See All in Technology
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
850
[2026-09-11]SREは誰のもの?運用エンジニアが始める 「SRE領域への越境」とチームの進化の軌跡 〜Road to NEXT CRE
tosite
0
190
GoにおけるFFIのこれまでとこれから
goccy
5
2.6k
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
970
銀行勘定系システムにおける開発プロセス刷新×AIによる環境モダナイゼーション / Development Process Transformation and AI-Driven Environment Modernization
muit
0
1.2k
10分で知る最近のOmarchy
komagata
0
280
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/6 - 2026/8
oracle4engineer
PRO
0
200
Deploying a Full-Stack Bun-Native Framework on Cloudflare Workers
7nohe
0
160
AI 時代のスタートアップエコシステ厶から考究する技術的負債との向き合い方
m3m0r7
PRO
2
950
すぐできる衛星通信対応 あとは山奥に行くだけ
tatetate55
0
110
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1.1k
Sigmaユーザーのための有用リソース一挙公開 & Sigmaで使えるMCP #sigma_ucj /useful-resources-for-sigma-computing-users-and-mcps-with-sigma
shinyaa31
0
210
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Facilitating Awesome Meetings
lara
57
7.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Bash Introduction
62gerente
615
220k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Balancing Empowerment & Direction
lara
6
1.3k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
Transcript
Dynamic Inventoryと参照変数 Ansible Meetup Tokyo 2014.09 @bungoume
内容 • 話すこと • Dynamic Inventory(EC2)について • 環境ごとに変数を使い分けるプラクティス • 話さないこと
• Ansible変数展開の順序
Dynamic Inventoryとは • Hostsをスクリプトで動的生成 • EC2やGCE, Zabbixなどの外部リソースからHostsを生成できる • プラグインとして用意 •
https://github.com/ansible/ansible/tree/devel/plugins/inventory • EC2.pyの場合 • タグやセキュリティグループ、リージョンなどを元にホストグループを管理 • ec2.iniで対象リージョンを制限したり、フィルタをかけたりできる • hostsとして利用できる • hosts/ ec2 ec2.ini • ansible-playbook –i hosts webservers.yml
EC2のAnsible管理用タグ付け例 • タグを用いて管理 • タグの例 • hostname: dbserver01a • env:
production, dev • role: webserver, dbserver • number: 01, 02, … • group: a, b, …. • ec2モジュールでインスタンス起動時にタグ付け or 手動でタグ付け • タグを指定してplaybook実行 • 例:ゾーンBにあるdev環境のwebserverにplaybookを実行 • ansible-playbook –i hosts webservers.yml --limit tag_env_dev:&ap-northeast-1b
こういうことがしたい • 環境とホストグループによって 変数の値を切り替えたい • 例: monitoring roleのlog_server変数(送り先) • production
の webserver は 10.0.1.100 • production の dbserver は 10.0.1.101 • dev の webserver は 10.0.2.100 • dev の dbserver は 10.0.2.101 • limitのand実行では難しい(playbook内で条件分岐が必要になる) 10.0.1.100 10.0.1.101 10.0.2.100 10.0.2.101
思いついた方法(2つ) • 方法1: inventory varsを使う • 方法2: vars_filesを使い、うまいこと読み込む
• hostsディレクトリに変数ファイルを置く hosts/ dev/ ec2 (ec2.py) ec2.ini (instance_filters = tag:env=dev)
group_vars/webserver (変数yaml) production/ …. group_vars/webserver (変数yaml) webservers.yml (playbook) • cat hosts/dev/group_vars/webserver --- log_server: 10.0.2.100 方法1: inventory varsを使う
- hosts: tag_role_webserver user: ec2-user tasks: - debug: var=log_server 方法1:
inventory varsを使う • Playbook ( webservers.yml ) • 実行 • ansible-playbook –i hosts/dev webservers.yml • group_vars/webserverを読み込み、 hosts/production/group_vars/webserverで上書きする ~~~ TASK: [debug var=log_server] ******************************************************** ok: [10.0.2.1] => { “log_server": "10.0.2.100" }
hosts/ ec2, ec2.ini vars/ nothing.yml tag_role_webserver.yml tag_env_dev/ tag_role_webserver.yml webservers.yml (playbook)
方法2: vars_filesを使う • 以下の様なディレクトリ構成 • エラー回避用にnothing.ymlという空ファイルを用意しておく
方法2: vars_filesを使う • Playbook(webservers.yml)に以下を記述 • 実行 • ansible-playbook –i hosts
webservers.yml --limit tag_env_dev • まずtag_role_webserver.ymlがあれば読込み、 tag_env_dev/tag_role_webserver.ymlがあれば上書きする - hosts: tag_role_webserver user: ec2-user vars_files: - [“vars/{{ ec2_tag_role }}.yml”, vars/nothing.yml] - [“vars/{{ ec2_tag_env }}/{{ ec2_tag_role }}.yml”, vars/nothing.yml] tasks: - debug: var=log_server
まとめ • 方法1( inventory vars ) • playbookの書き換えが不要 • limitを忘れて全体実行するリスクがない
• Inventoryファイルと組み合わせても使いやすい • 方法2( vars_files ) • 多段に利用可能 • {{ ec2_tag_env }}/{{ ec2_tag_role }}/{{ ec2_tag_group }}.yml • 読込優先度が自由に変更できる • まずは方法1、変数が増え、複雑な場合は方法2が良い感じ • もっと良い方法があったら教えて下さい