LoginSignup
26
31

More than 5 years have passed since last update.

Ansible ~templateモジュール~

Last updated at Posted at 2014-11-22

Ansible Documentationのtemplateモジュールの内容のメモです。

Ansible Documentation

概要

  • テンプレートモジュールは、指定したテンプレートのファイルを設置する
  • テンプレートはJinja2というテンプレート言語で記述される

オプション

頻度 パラメータ 必須 デフォルト値 選択肢 説明
backup no no yes
no
コピー前に元ファイルのバックアップをタイムスタンプ情報を付加して取得する。
dest yes - - コピー先の絶対パスの指定。
force no yes yes
no
既にファイルが存在する場合置き換えない。(要確認)
group no - - chownコマンドで設定できる所有者グループの設定。
mode no - - chmodコマンドで設定できる権限設定。8進数の指定とシンボリックモード(例を参照)での指定が可能。
owner no - - chownコマンドで設定できる所有者ユーザの設定。
selevel no s0 - selinuxのレベル。
serole no - - selinuxのロール。
setype no - - selinuxのタイプ。
seuser no - - selinuxのユーザ。
src yes - - ローカルにあるJinja2テンプレートのパス。絶対パス、相対パスでの指定が可能。
validate no - - コピー前に実行される検証コマンド。検証するファイルのパスは例のように『%s』で指定することが可能。

example.yml
# Example from Ansible Playbooks
- template: src=/mytemplates/foo.j2 dest=/etc/file.conf owner=bin group=wheel mode=0644

# The same example, but using symbolic modes equivalent to 0644
- template: src=/mytemplates/foo.j2 dest=/etc/file.conf owner=bin group=wheel mode="u=rw,g=r,o=r"

# Copy a new "sudoers" file into place, after passing validation with visudo
- template: src=/mine/sudoers dest=/etc/sudoers validate='visudo -cf %s'

参考

26
31
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
31