LoginSignup
7
11

More than 5 years have passed since last update.

Ansible ~replaceモジュール~

Posted at

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

Ansible Documentation

概要

  • replaceモジュールは、ファイル内で一致するパターンの置き換えをする。

オプション

頻度 パラメータ 必須 デフォルト値 選択肢 説明
backup no no yes
no
コピー前に元ファイルのバックアップをタイムスタンプ情報を付加して取得する。
dest yes - - 置換するファイルのパスを指定。
follow no no yes
no
既にファイルが存在する場合置き換えない。(要確認)
group no - - chownコマンドで設定できる所有者グループの設定。
mode no - - chmodコマンドで設定できる権限設定。8進数の指定とシンボリックモード(例を参照)での指定が可能。
others no - - fileモジュールで容認された全ての引数を指定できる。(要確認)
owner no - - chownコマンドで設定できる所有者ユーザの設定。
regexp yes - - 正規表現の指定。Pythonの正規表現を使用。
http://docs.python.org/2/library/re.html
replace no - - 置き換え文字の指定。設定しなかった場合、マッチした文字は削除される。
selevel no s0 - selinuxのレベル。
serole no - - selinuxのロール。
setype no - - selinuxのタイプ。
seuser no - - selinuxのユーザ。
validate no None - 置換前に実行される検証コマンド。

example.yml
- replace: dest=/etc/hosts regexp='(\s+)old\.host\.name(\s+.*)?$' replace='\1new.host.name\2' backup=yes

- replace: dest=/home/jdoe/.ssh/known_hosts regexp='^old\.host\.name[^\n]*\n' owner=jdoe group=jdoe mode=644

- replace: dest=/etc/apache/ports regexp='^(NameVirtualHost|Listen)\s+80\s*$' replace='\1 127.0.0.1:8080' validate='/usr/sbin/apache2ctl -f %s -t'

参考

7
11
0

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
7
11