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
19k
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
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
170
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
200
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
280
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
880
APIとはなにか
mikanichinose
0
100
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
37
15k
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
360
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
400
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
480
Featured
See All Featured
It's Worth the Effort
3n
183
28k
Practical Orchestrator
shlominoach
186
10k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
The Language of Interfaces
destraynor
154
24k
RailsConf 2023
tenderlove
29
940
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
BBQ
matthewcrist
85
9.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Docker and Python
trallard
42
3.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
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 !