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で構成管理。〜たったひとつの冴えたやりかた〜
Search
Tomohiko Isobe
January 09, 2018
Technology
12
18k
Ansibleで構成管理。〜たったひとつの冴えたやりかた〜
https://ljstudy.connpass.com/event/71037/
でのLT資料です。
Tomohiko Isobe
January 09, 2018
Tweet
Share
More Decks by Tomohiko Isobe
See All by Tomohiko Isobe
今さらだけど、group_varsとhost_varsについて一言言いたい
isobetomohiko
2
1.5k
Ansible-Vaultはこう使え!
isobetomohiko
1
420
あえて、AnsibleでRDSを構築してみる
isobetomohiko
0
270
Other Decks in Technology
See All in Technology
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.2k
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.2k
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
第3回Snowflake女子会_LT登壇資料(合成データ)_Taro_CCCMK
tarotaro0129
0
190
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
200
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
180
20241220_S3 tablesの使い方を検証してみた
handy
4
390
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
530
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
230
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
Featured
See All Featured
Statistics for Hackers
jakevdp
796
220k
Unsuck your backbone
ammeep
669
57k
Documentation Writing (for coders)
carmenintech
66
4.5k
Typedesign – Prime Four
hannesfritz
40
2.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
Building an army of robots
kneath
302
44k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Designing for humans not robots
tammielis
250
25k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Transcript
AnsibleͰߏཧɻ ʙͨͬͨͻͱͭͷࡓ͑ͨΓ͔ͨʙ 2018.1.9 ৽ఆ൪ʂAnsible ͱZabbixͰ࣮ݱ͢Δ࣍ੈӡ༻ཧ ү෦ஐ
Who am I ? • ү෦ ஐ (Tomohiko Isobe) •
Infrastructure EngineerˏΫϦχΧϧɾϓϥοτϑΥʔϜג ࣜձࣾ(2017.10-) • ౡࠜݝग़ • Job Hopperʢݱࡏ8ࣾ…ʣ • Favorites: ࢙ɾઓΊ͙ΓɺϑΝϛϨε https://clipla.jp
Ansibleͬͯ·͢ΑͶ
͜Μͳײ͡?
Infrastructure as Code !
None
ͦΕͬͯ ʮߏஙखॱʯͷཧͰʁ
αʔόͷʮߏʯΛ ཧ͍ͨ͠
ʮߏཧʯͱݴ͑
͔ͭͯɺ͜ͷੈʹ ʮύϥϝʔλγʔτʯ ͳΔͷ͕͋ͬͨ
͜Μͳͷ
ʑͷӡ༻
ύϥϝʔλγʔτɺ ߋ৽͠ͱ͖·ͨ͠❤
͋Δͷ͜ͱ
None
αʔόͷઃఆ͕ɺ ύϥϝʔλγʔτͱҧ͏…
ͪΌΜͱαʔόೖͬ ͯ֬ೝ͠·ͨ͠ʁ
Ͳ͏͢Δ͔
ΩϥοͱͻΒΊ͍ͨ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ
PlaybookͱมΛ͚Δ
PlaybookͱมΛ͚Δ • Roleʹมॻ͔ͳ͍ʂ • ΠϯϕϯτϦϑΝΠϧʹॻ͔ͳ͍ʂ • ςϯϓϨʔτͷύϥϝʔλͰ͖Δ͚ͩม ʹʂ
Roleʹมॻ͔ͳ͍ʂ • Roleࡉׂ͔ͨ͘͠ํ͕൚༻ੑ͕ߴ·Δ • ͍͍ͪͪશ෦ͷRoleͷmain.ymlݟͯΒΜͳ͍
Roleʹมॻ͔ͳ͍ʂ • Roleࡉׂ͔ͨ͘͠ํ͕൚༻ੑ͕ߴ·Δ • ͍͍ͪͪશ෦ͷRoleͷmain.ymlݟͯΒΜͳ͍
Roleʹมॻ͔ͳ͍ʂ • Roleࡉׂ͔ͨ͘͠ํ͕൚༻ੑ͕ߴ·Δ • ͍͍ͪͪશ෦ͷRoleͷmain.ymlݟͯΒΜͳ͍ →
Roleʹมॻ͔ͳ͍ʂ • Roleࡉׂ͔ͨ͘͠ํ͕൚༻ੑ͕ߴ·Δ • ͍͍ͪͪશ෦ͷRoleͷmain.ymlݟͯΒΜͳ͍ → มߋָ͕
ΠϯϕϯτϦϑΝΠϧʹॻ͔ͳ͍ʂ • ֊తʹॻ͚ͳ͍ͷͰɺมάϧʔϓ͕૿͑ ΔͱಡΈͮΒ͍
ΠϯϕϯτϦϑΝΠϧʹॻ͔ͳ͍ʂ • ֊తʹॻ͚ͳ͍ͷͰɺมάϧʔϓ͕૿͑ ΔͱಡΈͮΒ͍
ΠϯϕϯτϦϑΝΠϧʹॻ͔ͳ͍ʂ • ֊తʹॻ͚ͳ͍ͷͰɺมάϧʔϓ͕૿͑ ΔͱಡΈͮΒ͍ ͭΒ͍ʜ
ςϯϓϨʔτͷύϥϝʔλͰ͖Δ ͚ͩมʹʂ • Roleͱ߹Θͤͯ൚༻ੑ্͕
ςϯϓϨʔτͷύϥϝʔλͰ͖Δ ͚ͩมʹʂ • Roleͱ߹Θͤͯ൚༻ੑ্͕ logrotateͷtemplate(ൈਮ)
ςϯϓϨʔτͷύϥϝʔλͰ͖Δ ͚ͩมʹʂ • Roleͱ߹Θͤͯ൚༻ੑ্͕ logrotateͷtemplate(ൈਮ) logrotateͷvars
PlaybookͱมΛ͚Δ • Roleʹมॻ͔ͳ͍ʂ • ΠϯϕϯτϦϑΝΠϧʹॻ͔ͳ͍ʂ • ςϯϓϨʔτͷύϥϝʔλͰ͖Δ͚ͩม ʹʂ
PlaybookͱมΛ͚Δ • Roleʹมॻ͔ͳ͍ʂ • ΠϯϕϯτϦϑΝΠϧʹॻ͔ͳ͍ʂ • ςϯϓϨʔτͷύϥϝʔλͰ͖Δ͚ͩม ʹʂ →ɹgroup_vars,host_varsʹॻ͘ʂ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ
hash_behaviour = merge
hash_behaviour = merge • มͷϚʔδϙϦγʔ • ansible.cfgͷ[defaults]Ͱઃఆ • σϑΥϧτ”replace”
hash_behaviour = merge • σϑΥϧτ(replace)ͷڍಈ + group_vars ༏ઌɿ host_vars ༏ઌɿߴ
hash_behaviour = merge • σϑΥϧτ(replace)ͷڍಈ + group_vars ༏ઌɿ host_vars ༏ઌɿߴ
→ key2͕ফ͑ͨ
hash_behaviour = merge • hash_behaviour=mergeͷڍಈ + group_vars ༏ઌɿ host_vars ༏ઌɿߴ
hash_behaviour = merge • hash_behaviour=mergeͷڍಈ + → group_vars ༏ઌɿ host_vars
༏ઌɿߴ key1্ॻ͖ key3͕Ճ
hash_behaviour = merge • γʔέϯε(Ϧετ)ཁૉ͕શ෦্ॻ͖͞Εͯ ͠·͏ͷͰҙ + group_vars ༏ઌɿ host_vars
༏ઌɿߴ
hash_behaviour = merge • γʔέϯε(Ϧετ)ཁૉ͕શ෦্ॻ͖͞Εͯ ͠·͏ͷͰҙ + → group_vars ༏ઌɿ
host_vars ༏ઌɿߴ list͝ͱ্ॻ͖
hash_behaviour = merge • มͷޮతͳཧ͕Մೳ
hash_behaviour = merge • มͷޮతͳཧ͕Մೳ group_vars/all.yml(શαʔόڞ௨)
hash_behaviour = merge • มͷޮతͳཧ͕Մೳ group_vars/all.yml(શαʔόڞ௨) group_vars/webservers.yml(webαʔόڞ௨) +
hash_behaviour = merge • มͷޮతͳཧ͕Մೳ group_vars/all.yml(શαʔόڞ௨) group_vars/webservers.yml(webαʔόڞ௨) host_vars/web01.yml(web01ݻ༗ઃఆ) + +
hash_behaviour = merge • มͷޮతͳཧ͕Մೳ group_vars/all.yml(શαʔόڞ௨) group_vars/webservers.yml(webαʔόڞ௨) host_vars/web01.yml(web01ݻ༗ઃఆ) ࠷ऴతʹweb01ʹద༻͞ΕΔม →
+ +
hash_behaviour = merge • Γ͗͢ҙ • ༧ظͤ͵্ॻ͖ • ෳgroup_varsͷద༻ॱ •
ม͕ࢄ͞Εͯ͠·͏
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ
ม,FactҰཡΛग़ྗͯ͠ཧ
ม,FactҰཡΛग़ྗͯ͠ཧ • merge͞ΕͨมΛग़ྗ • Fact ?
merge͞ΕͨมΛग़ྗ • templateϞδϡʔϧͰɺlocalhostʹશมΛग़ ྗ͢Δ • શมΛ”my_vars(ҙ)”ҎԼͷ֊ߏʹ͢ Δʢॏཁʂʣ • {{ hostvars[inventory_hostname]["my_vars"]
| to_nice_yaml | indent(2, True) }}
merge͞ΕͨมΛग़ྗ • Playbook ESZSVOͰग़ྗ
merge͞ΕͨมΛग़ྗ • template
merge͞ΕͨมΛग़ྗ • ͜Μͳײ͡
Fact ? • SetupϞδϡʔϧʹΑΓऩू͞ΕΔରϗετ ͷڥใ • ansible_*ͱͯ͠ࢀরՄೳ
͔ͤͬ͘ͳΜͰFactग़ྗ͠·͔͢ • ྫ͑ɺΧʔωϧͷόʔδϣϯͳΒ {{ hostvars[inventory_hostname] [ansible_kernel] }} • ͍ͬͺ͍͋ΔͷͰཧ͍ͨ͠ใΛ͓ΈͰ
͔ͤͬ͘ͳΜͰFactग़ྗ͠·͔͢ • ͜Μͳײ͡
ࠓͷαʔόͷߏɺ ͜͏ͳͬͯ·͢❤
ύϥϝʔλγʔτײʂ
͜ΕΛgitͰཧ͢Ε
ߏཧʂ
·ͱΊ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ →ߏஙखॱͱύϥϝʔλΛׂ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ →ߏஙखॱͱύϥϝʔλΛׂ
→ύϥϝʔλΛޮతʹཧ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ ≒
ύϥϝʔλγʔτ →ߏஙखॱͱύϥϝʔλΛׂ →ύϥϝʔλΛޮతʹཧ
ࡓ͑ͨΓ͔ͨ • PlaybookͱมΛ͚Δ • hash_behaviour = merge • ม,FactҰཡΛग़ྗͯ͠ཧ ≒
ύϥϝʔλγʔτˠgitཧ →ߏஙखॱͱύϥϝʔλΛׂ →ύϥϝʔλΛޮతʹཧ
એ • ଞʹAnsibleωλॻ͍ͯ·͢ • https://qiita.com/isobecky74
Thank you !