SlideShare a Scribd company logo
1 of 27
Download to read offline
マイベストVariables
設定場所
(異論、反論Welcome!)
Ansible Night in Tokyo 2018.09 LT
オイシックス・ラ・大地(株) 林 如弥
最初に
お伝えしておきたいの
ですが
タイトルの
タイトルの これ
皆様には
皆様のベストが
きっとあるはず
今から話す内容が
何かの参考になれば
幸いです
22
22
この数字、何の数か
ぴんと来ます
でしょうか?
22
Ansibleにおいて、
variablesが設定可能な
場所の数です
https://docs.ansible.com/ansible/2.6/user_guide/playbooks_variables.html#variable-scopes
公式ドキュメントより:
Variable Precedence: Where Should I Put A Variable?
(変数の優位順:どこで変数を設定すると良いの?)
22
動的なcommand line
values、vars_promptを
除いても、20箇所で
変数定義が可能です
柔軟性には感謝しつつも
乱用すれば「スパゲッティ
コード」になること
請け合い
― Figure out where to define a variable,
and don’t make it complicated. ―
 ( 変数を定義する場所を特定し、
           複雑にするな)
公式ドキュメントより:
Variable Precedence: Where Should I Put A Variable?
(変数の優位順:どこで変数を設定すると良いの?)
https://docs.ansible.com/ansible/2.6/user_guide/playbooks_variables.html#variable-scopes
そこでプラクティス
group_vars/
group1.yml
group2.yml
host_vars/
hostname1.yml
hostname2.yml
roles/
common/
vars/
main.yml
defaults/
main.yml
公式ベストプラクティスでは
https://docs.ansible.com/ansible/2.6/user_guide/playbooks_best_practices.html#best-practices
group_vars/
group1.yml    ←グループ単位の変数
group2.yml
host_vars/
hostname1.yml    ←ホスト単位の変数
hostname2.yml
roles/
common/
vars/    ←ロール単位の変数
main.yml
defaults/    ←ロール単位のデフォルト変数
main.yml
公式ベストプラクティスでは
https://docs.ansible.com/ansible/2.6/user_guide/playbooks_best_practices.html#best-practices
group_vars/
group1.yml    ←グループ単位の変数
group2.yml (ミドルウェアのバージョンなど)
host_vars/
hostname1.yml    ←ホスト単位の変数
hostname2.yml    (特定ホストだけデバッグツール有効など)
roles/
common/
vars/    ←ロール単位の変数
main.yml  (ループ要素の切り出しなど)
defaults/    ←ロール単位のデフォルト変数
main.yml    (全変数の一覧化、再利用性高めるなど)
公式ベストプラクティスでは
https://docs.ansible.com/ansible/2.6/user_guide/playbooks_best_practices.html#best-practices
「...変更する必要のあるパラメータが十数個程度であれば、
Inventoryファイルに記述した方が見通しがよくなり...」
[all:vars]
ketchup_host=192.168.33.12
ketchup_nginx_host=192.168.33.13
ketchup_port=80
[vagrant:vars]
ansible_connection=local
instance_provider=vagrant
インフラCI実践ガイドでは
https://www.shoeisha.co.jp/book/detail/9784798155128
https://github.com/infra-ci-book/ketchup-vagrant-ansible/blob/master/hosts/ketchup/inventory
マイベスト
プラクティス
group_vars/
all.yml    ←共通設定(基本これを育てる)
host_vars/
hostname1.yml    ←ホスト単位の変数
hostname2.yml     (必要なら作る)
vars/
site1/ ←各サイト(複数のWebサービスがある)単位で
dev.yml ←開発、本番環境の差異を定義
prd.yml
site2/
roles/     ←ロール内では変数は定義しない
マイベストプラクティス
https://docs.ansible.com/ansible/2.6/user_guide/playbooks_best_practices.html#best-practices
Point.1
group_vars/all.yml
● とにかくall.ymlを育てる
○ 共通変数は全てall.yml
○ all.yml以外は置かない
○ all.ymlを見れば全体を知れる
Point.2
host_vars/
● 必要なら作る
○ 必要なくなれば消す
○ 極力作らない
Point.3
roles/
● 変数ファイルを持たない
○ 処理のみ記述する場所と定義
○ 調査時に潜る場所を減らす
Point.4
vars/site/xxx.yml
● サイト/環境の差異のみ記載
○ 基本はgroup_vars/all.ymlで定義され
ている
○ 違いが一目瞭然
なぜこうしたのか
● 手動構築の古株サーバが大半現役
● 基盤刷新を機に標準化を行いたい
● all.ymlで標準を定義
● 徐々にhost_varsを消していく
「標準化、統合への意志」をディレクトリ構成
へ反映 (ディレクトリ構成における”逆コンウェイ戦略”といってもいいかも?)
実は絶賛試行中...
● host_varsなかなか消せない(TT
● ついgroup_vars作りたくなる(^^;
● 今は突き進む予定(๑•̀ㅂ•́)‫و‬
● 仲間募集してます(><
(略称:オイラ大地)
まとめ
● ansibleのvariablesはとても柔軟
● 複雑にならないようにルールを決める
● ディレクトリ構造に戦略を持つ(のもありか
も)
ご静聴ありがとうございました m(_ _)m

More Related Content

More from Yukiya Hayashi

How did you start learning Azure
 How did you start learning Azure How did you start learning Azure
How did you start learning AzureYukiya Hayashi
 
My feelings of going to the first conference overseas
My feelings of going to the first conference overseasMy feelings of going to the first conference overseas
My feelings of going to the first conference overseasYukiya Hayashi
 
Let's split text by awk command
Let's split text by awk commandLet's split text by awk command
Let's split text by awk commandYukiya Hayashi
 
What i feel when began use AWS CodePipeline as GitLab Ci user
What i feel when began use AWS CodePipeline as GitLab Ci userWhat i feel when began use AWS CodePipeline as GitLab Ci user
What i feel when began use AWS CodePipeline as GitLab Ci userYukiya Hayashi
 
How to get rid of terraform plan diffs
How to get rid of terraform plan diffsHow to get rid of terraform plan diffs
How to get rid of terraform plan diffsYukiya Hayashi
 
Task and Time monitoring with Backlog and Toggl
Task and Time monitoring with Backlog and TogglTask and Time monitoring with Backlog and Toggl
Task and Time monitoring with Backlog and TogglYukiya Hayashi
 
Oiradaichi's Akamai Journey
Oiradaichi's Akamai Journey Oiradaichi's Akamai Journey
Oiradaichi's Akamai Journey Yukiya Hayashi
 
What does the monitoring tool use at oisix ra daichi?
What does the monitoring tool use at oisix ra daichi?What does the monitoring tool use at oisix ra daichi?
What does the monitoring tool use at oisix ra daichi?Yukiya Hayashi
 
We love backlog ! in reCap event.
We love backlog ! in reCap event.We love backlog ! in reCap event.
We love backlog ! in reCap event.Yukiya Hayashi
 
What we expect of neo4j
What we expect of neo4jWhat we expect of neo4j
What we expect of neo4jYukiya Hayashi
 
Backlog World 2019 LT - We love backlog !
Backlog World 2019 LT - We love backlog !Backlog World 2019 LT - We love backlog !
Backlog World 2019 LT - We love backlog !Yukiya Hayashi
 
Introduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing DockerfilesIntroduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing DockerfilesYukiya Hayashi
 
postgresql conference 2018 on-premise to rds
postgresql conference 2018 on-premise to rdspostgresql conference 2018 on-premise to rds
postgresql conference 2018 on-premise to rdsYukiya Hayashi
 
Zabbix Conference Japan 2018 LT Configure by Ansible
Zabbix Conference Japan 2018 LT Configure by AnsibleZabbix Conference Japan 2018 LT Configure by Ansible
Zabbix Conference Japan 2018 LT Configure by AnsibleYukiya Hayashi
 
Jenkins User Conference 2018 Tokyo LT
Jenkins User Conference 2018 Tokyo LTJenkins User Conference 2018 Tokyo LT
Jenkins User Conference 2018 Tokyo LTYukiya Hayashi
 
ジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりました
ジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりましたジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりました
ジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりましたYukiya Hayashi
 
20171117 redminetokyo13
20171117 redminetokyo1320171117 redminetokyo13
20171117 redminetokyo13Yukiya Hayashi
 
PostgreSQL DBのバックアップを一元化しよう
PostgreSQL DBのバックアップを一元化しようPostgreSQL DBのバックアップを一元化しよう
PostgreSQL DBのバックアップを一元化しようYukiya Hayashi
 
Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話
Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話
Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話Yukiya Hayashi
 

More from Yukiya Hayashi (20)

How did you start learning Azure
 How did you start learning Azure How did you start learning Azure
How did you start learning Azure
 
My feelings of going to the first conference overseas
My feelings of going to the first conference overseasMy feelings of going to the first conference overseas
My feelings of going to the first conference overseas
 
Let's split text by awk command
Let's split text by awk commandLet's split text by awk command
Let's split text by awk command
 
What i feel when began use AWS CodePipeline as GitLab Ci user
What i feel when began use AWS CodePipeline as GitLab Ci userWhat i feel when began use AWS CodePipeline as GitLab Ci user
What i feel when began use AWS CodePipeline as GitLab Ci user
 
How to get rid of terraform plan diffs
How to get rid of terraform plan diffsHow to get rid of terraform plan diffs
How to get rid of terraform plan diffs
 
Task and Time monitoring with Backlog and Toggl
Task and Time monitoring with Backlog and TogglTask and Time monitoring with Backlog and Toggl
Task and Time monitoring with Backlog and Toggl
 
Oiradaichi's Akamai Journey
Oiradaichi's Akamai Journey Oiradaichi's Akamai Journey
Oiradaichi's Akamai Journey
 
What does the monitoring tool use at oisix ra daichi?
What does the monitoring tool use at oisix ra daichi?What does the monitoring tool use at oisix ra daichi?
What does the monitoring tool use at oisix ra daichi?
 
We love backlog ! in reCap event.
We love backlog ! in reCap event.We love backlog ! in reCap event.
We love backlog ! in reCap event.
 
What we expect of neo4j
What we expect of neo4jWhat we expect of neo4j
What we expect of neo4j
 
Backlog World 2019 LT - We love backlog !
Backlog World 2019 LT - We love backlog !Backlog World 2019 LT - We love backlog !
Backlog World 2019 LT - We love backlog !
 
20190116 neo4jug-lt
20190116 neo4jug-lt20190116 neo4jug-lt
20190116 neo4jug-lt
 
Introduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing DockerfilesIntroduce that Best practices for writing Dockerfiles
Introduce that Best practices for writing Dockerfiles
 
postgresql conference 2018 on-premise to rds
postgresql conference 2018 on-premise to rdspostgresql conference 2018 on-premise to rds
postgresql conference 2018 on-premise to rds
 
Zabbix Conference Japan 2018 LT Configure by Ansible
Zabbix Conference Japan 2018 LT Configure by AnsibleZabbix Conference Japan 2018 LT Configure by Ansible
Zabbix Conference Japan 2018 LT Configure by Ansible
 
Jenkins User Conference 2018 Tokyo LT
Jenkins User Conference 2018 Tokyo LTJenkins User Conference 2018 Tokyo LT
Jenkins User Conference 2018 Tokyo LT
 
ジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりました
ジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりましたジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりました
ジョブ管理でcronは限界があったので”Rundeck”を使ってハッピーになりました
 
20171117 redminetokyo13
20171117 redminetokyo1320171117 redminetokyo13
20171117 redminetokyo13
 
PostgreSQL DBのバックアップを一元化しよう
PostgreSQL DBのバックアップを一元化しようPostgreSQL DBのバックアップを一元化しよう
PostgreSQL DBのバックアップを一元化しよう
 
Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話
Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話
Attrasian JIRAをv6.3.15からv7.3.2へバージョンアップした話
 

Recently uploaded

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)UEHARA, Tetsutaro
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...博三 太田
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineerYuki Kikuchi
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfFumieNakayama
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfFumieNakayama
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?akihisamiyanaga1
 

Recently uploaded (14)

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
 

ansiblejp-best-variables-place