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.

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.

2
  • 1
    I'd suggest using lineinfile instead of replace.
    – Panki
    Feb 17 '20 at 14:36
  • @Panik can u plz share an example... I'm more concern about proper regex than the module...
    – Siva
    Feb 17 '20 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.