Ansible-如果不存在,则插入行,并且不';如果存在以空格分隔的行,则不插入
我使用lineinfle模块插入一条不存在的线,但当它存在多个空格时,它仍然插入一条线 输入:Ansible-如果不存在,则插入行,并且不';如果存在以空格分隔的行,则不插入,ansible,Ansible,我使用lineinfle模块插入一条不存在的线,但当它存在多个空格时,它仍然插入一条线 输入: one two three (not exists) < Insert one two three < Don't insert (it's correct) one two three < Don't insert (having same words but multiple spaces) - lineinfile: path: /somefi
one two three
(not exists) < Insert
one two three < Don't insert (it's correct)
one two three < Don't insert (having same words but multiple spaces)
- lineinfile:
path: /somefile
line: 'one two three'
Before : one two three
After : one two three
one two three
期望:
one two three
(not exists) < Insert
one two three < Don't insert (it's correct)
one two three < Don't insert (having same words but multiple spaces)
- lineinfile:
path: /somefile
line: 'one two three'
Before : one two three
After : one two three
one two three
我的输出:
one two three
(not exists) < Insert
one two three < Don't insert (it's correct)
one two three < Don't insert (having same words but multiple spaces)
- lineinfile:
path: /somefile
line: 'one two three'
Before : one two three
After : one two three
one two three
问:“期待”
给定test.txt文件
shell>cat test.txt
123
此任务的剧本给出了
shell>ansible剧本pb.yml
shell>cat test.txt
123
456
作为下一个示例,下面的regexp
给出了相同的结果,并将序列限制为仅空白。单词之间必须至少有一个空格
-lineinfle:
路径:test.txt
regexp:“^(\s*){{item.0}(\s+{{item.1}}(\s+{{item.2}}(\s*)$”
行:“{item.0}}{{item.1}{{{item.2}”
循环:
-一、二、三
-四、五、六
背景参考 可以保留现有线条的间距。看见但是,不存在的行将不会被添加
-lineinfle:
背景:是的
路径:test.txt
regexp:“^(.*){{item.0}}(.*){{item.1}(.*){{item.2}}(.*)”
行:“{item.0}}\2{{item.1}}\3{{item.2}”
循环:
-一、二、三
-四、五、六
例如,给定相同的文件
shell>cat test.txt
123
具有此任务的剧本跳过迭代,并且不做任何更改
shell>ansible剧本pb.yml
shell>cat test.txt
123