2016-07-21 3 views
0

(1とし、取り外しまたは交換が行をコメント)行のブロック:lineinfileで複数行のマッチがサポートされていますか?私が一致したい

daemon.*;mail.*;\ 
     news.err;\ 
     *.=debug;*.=info;\ 
     *.=notice;*.=warn  |/dev/xconsole 

私はdaemon(?:.|\n)*xconsolelineinfileでそれらを一致させることを試みたが、試合は発生していないようです:交換用のラインを追加が、古い行が残っている:

- name: remove xconsole from rsyslog.conf 
    lineinfile: 
     dest: /etc/rsyslog.conf 
     regexp: daemon(?:.|\n)*xconsole 
     state: absent 
     # also tried to add the next line to replace with a comment 
     #line: "# removed by ansible" 

は、このようなブロックがサポートされていますか?

注:私は約blockinfileを知っています。これは、区切りブロックの追加/削除を管理するのに最適です。私は彼らが非不可能な挿入ブロック(正規表現にマッチしている)で動作するとは思わない。

答えて

2

いいえ、lineinfile検索式行、module's source codeを参照してください。

あなたは、テキストを置換/削除replaceモジュールを使用する必要がある場合 - それは、複数行の正規表現を使用して、例えば:

- name: remove xconsole from rsyslog.conf 
    replace: 
     dest: /etc/rsyslog.conf 
     # ensure regex is lazy! 
     regexp: daemon[\S\s]*?xconsole 
     replace: "# removed by ansible" 
関連する問題