Skip to content

Instantly share code, notes, and snippets.

@komeda-shinji
Created March 5, 2015 12:04
Show Gist options
  • Save komeda-shinji/0ac2d7866e01b23aaf48 to your computer and use it in GitHub Desktop.
Save komeda-shinji/0ac2d7866e01b23aaf48 to your computer and use it in GitHub Desktop.
Ansibleで設定ファイルの行を書き換える(コンテキスト編) ref: http://qiita.com/komeda-shinji/items/e24fab2ab0f2f5858111
- hosts: servers
vars:
httpd_conf: /etc/apache2/apache2.conf
tasks:
- name: lookup DocumentRoot in VirtualHost
shell: sed -n '/^<VirtualHost \*:80>/,/<\/VirtualHost>/{/DocumentRoot/p; }' {{httpd_conf}}
register: lookup
changed_when: False
- name: change httpd.conf
shell: sed -i$(date +'.%Y-%m-%d@%H:%M~') '/^<VirtualHost \*:80>/,/<\/VirtualHost>/{s/\(DocumentRoot[[:space:]]*\).*$/\1\/var\/www/; }' {{httpd_conf}}
when: lookup.stdout != ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment