🍣
Ansibleのインベントリ(hosts)を作る
いつもなんとなく作ってきてたけど、これはいいなというのが見えたのでメモ。
Ansibleの公式にはこんな感じで書かれている。
mail.example.com
[webservers]
foo.example.com
bar.example.com
[dbservers]
one.example.com
two.example.com
three.example.com
実はこれあんまり使い勝手よくないので、下記のようにするとよい。
[app01:children]
webservers
dbservers
[webservers]
foo.example.com
bar.example.com
[dbservers]
one.example.com
two.example.com
three.example.com
[hosts]
one.example.com ansible_host=10.10.53.*** # コメント
two.example.com ansible_host=10.10.53.*** # コメント
three.example.com ansible_host=10.10.53.*** # コメント
mail.example.com
- ホスト単体の定義は末尾でまとめてやったほうが視認性がいい
-
:children
無しでホストをグループ化できる - グループ化したホストを
:children
でさらにグループ化する
インベントリエイリアスを便利に使った方法かもしれない。
Discussion