ansible replace 模块匹配多行 MULTILINE mode


The regular expression to look for in the contents of the file. Uses Python regular expressions; see Uses MULTILINE mode, which means ^ and $ match the beginning and end of the file, as well as the beginning and end respectively of each line of the file.
Does not use DOTALL, which means the . special character matches any character except newlines. A common mistake is to assume that a negated character set like [^#] will also not match newlines. In order to exclude newlines, they must be added to the set like [^#\n].
Note that, as of ansible 2, short form tasks should have any escape sequences backslash-escaped in order to prevent them being parsed as string literal escapes. See the examples.

repalce 默认使用python正则的multiline 模式,是支持匹配多行的
但是 .+ 这种无法匹配是因为 . 本身不匹配\n这类特殊字符
换用 [^#] 这中写法后,即可匹配多行
如果排除换行,要把\n加入用 [^#\n] 这中写法

© 2018, 新之助meow. 原创文章转载请注明: 转载自

0.00 avg. rating (0% score) - 0 votes