0

I would like to update http log format using Ansible.

Current config looks like:

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

Need to update to the following:

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

Tried using the replace module. But it didn't edit the file...

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

Note: I have copied httpd.conf to /tmp for testing.

1 Answer 1

0

End up with below playbook

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

plz, let me know if we can do with better regex.

1
  • 1
    I'd suggest using lineinfile instead of replace.
    – Panki
    Feb 17, 2020 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .