37. 利用可能なモジュール一覧の確認
モジュールに関するドキュメントは`ansible-doc`コマンドで参照
Ansibleモジュール
$ ansible-doc -l
$ ansible-doc file
Sets attributes of files, symlinks, and directories, or removes
files/symlinks/directories. Many other modules support the same
options as the [file] module - including [copy], [template], and [assemble].
Options (= is mandatory):
- follow
This flag indicates that filesystem links, if they exist, should
be followed.
(Choices: yes, no)[Default: no]
- force
force the creation of the symlinks in two cases: the source file
does not exist (but will appear later); the destination exists
and is a file (so, we need to unlink the "path" file and create
モジュール名
43. vars / templates
varsの値定義箇所は複数存在し、各優先度が複雑な為に注意が必要
● role defaults
● inventory vars
● inventory group_vars
● inventory host_vars
● playbook group_vars
● playbook host_vars
● host facts
● play vars
● play vars_prompt
● play vars_files
● registered vars
● set_facts
● role and include vars
● block vars (only for tasks in block)
● task vars (only for the task)
● extra vars (always win precedence)
low
priority
high
46. Best Practice
production # inventory file for production servers
staging # inventory file for staging environment
group_vars/
group1 # here we assign variables to particular groups
group2 # ""
host_vars/
hostname1 # if systems need specific variables, put them here
hostname2 # ""
library/ # if any custom modules, put them here (optional)
filter_plugins/ # if any custom filter plugins, put them here (optional)
site.yml # master playbook
webservers.yml # playbook for webserver tier
dbservers.yml # playbook for dbserver tier
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
vars/ #
main.yml # <-- variables associated with this role
defaults/ #
main.yml # <-- default lower priority variables for this role
meta/ #
main.yml # <-- role dependencies
library/ # roles can also include custom modules
lookup_plugins/ # or other types of plugins, like lookup in this case
webtier/ # same kind of structure as "common" was above, done for the webtier
role
monitoring/ # ""
fooapp/ # ""
公式のAnsibleディレクトリ構成の
ベストプラクティス
マルチステージに対応
production / staging