且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ansible lineinfile正则表达式多行

更新时间:2023-02-17 23:13:54

我设法通过稍微改善@ mattyoung-redhatmatt的答案来做到这一点.事实证明,replace模块可以处理多行正则表达式和反向引用:

I managed to do exactly this by slightly improving @mattyoung-redhatmatt's answer. As it turns out, the replace module handles multi line regular expressions and backreferences just fine:

- name: AllowOverride all
  replace:
    dest=/etc/apache2/apache2.conf
    regexp='(<[dD]irectory /var/www/>[^<]*)AllowOverride None'
    replace='\1AllowOverride All'
    backup=yes
  sudo: yes
  notify:
    - restart apache