Sollosa Asked: 2022-10-10 07:29:05 +0800 CST2022-10-10 07:29:05 +0800 CST 2022-10-10 07:29:05 +0800 CST ansible lineinfile 模块以匹配 variable_value 772 如何通过 lineinfile 模块中的正则表达式参数匹配变量的值? - name: emptyline before search lineinfile: dest: ~/file insertbefore: '^{{ search_text }}$' line: '' 我在上面尝试了单引号/双引号,它似乎不起作用 ansible search 1 个回答 Voted Best Answer U880D 2022-10-10T23:09:34+08:002022-10-10T23:09:34+08:00 对于一个文件test.txt hello something test hello something 运行一个测试剧本,比如 --- - hosts: localhost become: false gather_facts: false vars: BEFORE: "test" tasks: - name: Add line before lineinfile: path: test.txt insertbefore: '^{{ BEFORE }}$' line: '' 结果输出为 hello something test hello something 预期的。
对于一个文件
test.txt
运行一个测试剧本,比如
结果输出为
预期的。