Ansible 2.5.5 - 在"替换"模块中的属性不起作用之前



我试图仅替换特定字符串后的第一次出现。然而,ansible总是匹配所有的出现。文件如下:

这是我的可见任务:

- name: Update minPoolSize for CWTxDataSource dataSource
replace:
dest: "{{ op_db_path }}"
after: ".*CWTxDataSourceXA"
regexp: "^.*minPoolSize=.*$"
replace: '        <connectionManager maxPoolSize="750" minPoolSize="20" />'
backup: yes
<dataSource jndiName="CWTxDataSource">
<connectionManager maxPoolSize="750" minPoolSize="1" />
</dataSource>
<dataSource jndiName="UMDataSource">
<connectionManager maxPoolSize="750" minPoolSize="1" />
</dataSource>

在上面的示例中,两个connectionManager标记都将得到更新,这不是期望的行为?我怎么能更新我的regexp只更新第一场比赛??我尝试了replace模块中的before选项作为解决方案,但由于某种原因,这对我不起作用。

我在ansible docs中发现了下面这行:

# Prior to Ansible 2.7.10, using before and after in combination did the opposite of what was intended.

所以为了让我使用afterbefore作为一个解决方案,我必须颠倒它们的值:

- name: Update minPoolSize for CWTxDataSource dataSource
# after / before values are reversed in ansible < 2.7
replace:
path: "{{ op_db_path }}"
before: 'jndiName="CWTxDataSource"'
after: "</dataSource>"
regexp: 'minPoolSize="d+"'
replace: 'minPoolSize="{{ CWTxDS_minPoolSize }}"'

注意afterbefore的值没有真正的意义,但它的工作!

最新更新