ansible で設定ファイル内の文字列を置換したかったので、 lineinfile モジュールを試してみました。 lineinfile http://www.ansibleworks.com/docs/modules.html#lineinfile 対象サーバに以下のようなファイルを用意。 /tmp/test.conf foo bar baz bar bar bar foo このファイル内の文字列を置換してみます。 以下のような Playbook を作成しました。 lineinfile.yml - hosts: all user: root vars: target_file: /tmp/test.conf tasks: - name: lineinfile example task lineinfile: dest=${target_file} state=present regexp