ansibleを使用してhttpd confファイルを更新する方法

ansibleを使用してhttpd confファイルを更新する方法

Ansibleを使用してhttpログ形式を更新したいです。

現在の構成は次のとおりです。

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

次の内容で更新する必要があります。

LogFormat "%h %l %u %t %D %X \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combined

このモジュールを試してくださいreplace。しかし、ファイルの変更はできません...

---
- name: test
  hosts: testServer
  gather_facts: no
  tasks:
  - name: configure httpd
    replace:
      path: /tmp/httpd.conf
      regexp: 'LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined'
      replace: 'LogFormat "%h %l %u %t %D %X \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combined'

httpd.conf注:テスト用にコピーしました/tmp

ベストアンサー1

最後に、次のスクリプトを取得しました。

---
- name: test
  hosts: testServer
  gather_facts: no
  tasks:
  - name: configure httpd
    replace:
      path: /tmp/httpd.conf
      regexp: '^LogFormat.*combined$'
      replace: 'LogFormat "%h %l %u %t %D %X \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combined'

より良い正規表現が利用可能かどうか教えてください。

おすすめ記事