Roleのディレクトリレイアウトとは、ドキュメントで説明されているDirectory Layoutのことです。
roles
の箇所を抜粋
roles/
common/ # this hierarchy represents a "role"
tasks/ #
main.yml # <-- tasks file can include smaller files if warranted
handlers/ #
main.yml # <-- handlers file
templates/ # <-- files for use with the template resource
ntp.conf.j2 # <------- templates end in .j2
files/ #
bar.txt # <-- files for use with the copy resource
foo.sh # <-- script files for use with the script resource
vars/ #
main.yml # <-- variables associated with this role
defaults/ #
main.yml # <-- default lower priority variables for this role
meta/ #
main.yml # <-- role dependencies
webtier/ # same kind of structure as "common" was above, done for the webtier role
monitoring/ # ""
fooapp/
tasks,handlers,templates... とフォルダ構成となっていて、一つのyamlファイルに書いていくよりも
このディレクトリ構成のほうが整理しやすくて良いです。
ただ、久しぶりにroleを作る時とか構成を忘れてしまいますよね。
毎回手打ちで作るのは面倒だし、typoしたらみっともないし、このディレクトリ作るためだけにshell作るのもなーと。
これ、実はansible-galaxy
コマンドのinit
サブコマンドを実行することで一通りつくってくれます。
ansible-galaxy init (your_role_name)
$ ansible-galaxy init myrole
$ tree myrole/
myrole/
├── README.md
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
tests
やmeta
も作られますが、不要なら削除してしまえばいいです。
ansible-galaxy
自体はAnsible Galaxyの操作を行うコマンドですが、
initが結構便利で、私は適当なroleを作る時でもこのコマンドで毎回作ってしまします。
良きAnsibleライフを!