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
260
Other Decks in Technology
See All in Technology
プロダクトチームへのSystem Risk Records導入・運用事例の紹介/Introduction and Case Studies on Implementing and Operating System Risk Records for Product Teams
taddy_919
1
170
MAMを軸とした動画ハンドリングにおけるAI活用前提の整備と次世代ビジョン / abema-ai-mam
cyberagentdevelopers
PRO
1
110
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
170
来年もre:Invent2024 に行きたいあなたへ - “集中”と“つながり”で楽しむ -
ny7760
0
460
Vueで Webコンポーネントを作って Reactで使う / 20241030-cloudsign-vuefes_after_night
bengo4com
4
2.5k
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
620
カメラを用いた店内計測におけるオプトインの仕組みの実現 / ai-optin-camera
cyberagentdevelopers
PRO
1
120
分布で見る効果検証入門 / ai-distributional-effect
cyberagentdevelopers
PRO
4
690
신뢰할 수 있는 AI 검색 엔진을 만들기 위한 Liner의 여정
huffon
0
300
クライアントサイドでよく使われる Debounce処理 をサーバサイドで3回実装した話
yoshiori
1
150
Jr. Championsになって、強く連携しながらAWSをもっと使いたい!~AWSに対する期待と行動~
amixedcolor
0
190
ガバメントクラウド先行事業中間報告を読み解く
sugiim
1
1.2k
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Why Our Code Smells
bkeepers
PRO
334
57k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Automating Front-end Workflow
addyosmani
1365
200k
We Have a Design System, Now What?
morganepeng
50
7.2k
For a Future-Friendly Web
brad_frost
175
9.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Statistics for Hackers
jakevdp
796
220k
Happy Clients
brianwarren
97
6.7k
Six Lessons from altMBA
skipperchong
26
3.5k
The Language of Interfaces
destraynor
154
24k
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 !