Skip to content

Instantly share code, notes, and snippets.

@komeda-shinji
Created February 28, 2015 13:55
Show Gist options
  • Save komeda-shinji/ca900bc8a42422194b0f to your computer and use it in GitHub Desktop.
Save komeda-shinji/ca900bc8a42422194b0f to your computer and use it in GitHub Desktop.
Ansibleで設定ファイルの行を書き換える ref: http://qiita.com/komeda-shinji/items/fafc46e27e0619cade14
- hosts: servers
vars:
httpd_conf: /etc/apache2/apache2.conf
tasks:
- name: grep %{Session}C
command: grep '^LogFormat[[:space:]].*%{Session}C.*[[:space:]]combined' {{httpd_conf}}
register: grep
ignore_errors: True
failed_when: False
changed_when: False
- name: change httpd.conf
lineinfile:
backup=yes
backrefs=yes
dest={{httpd_conf}}
state=present
regexp="^(LogFormat\s+\")(.*)(\"\s+combined)$"
line="\1\2 \\\\\"%{Session}C\\\\\" \3"
when: grep.rc == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment