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
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
6
670
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
2
280
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
TypeScript、上達の瞬間
sadnessojisan
46
13k
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
490
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
20
1.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Producing Creativity
orderedlist
PRO
341
39k
What's new in Ruby 2.0
geeforr
343
31k
Designing Experiences People Love
moore
138
23k
Designing the Hi-DPI Web
ddemaree
280
34k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Fireside Chat
paigeccino
34
3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Practical Orchestrator
shlominoach
186
10k
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 !