为什么 blockinfile with state=absent 对这些行不起作用?
Why does blockinfile with state=absent not work for these lines?
我有一个包含以下文本块的文件。我在文本块前后都有文本
other_user:
hash: JKJ;LKJA;LDKJF;LKJA;LKJIUR;JFKLJDQPIRQKJ;LKFJPOQJ
#password is: some_pw0
logstash:
hash: $fj;kdjjfajf;ajKFJ;dfj;dkfja;dfjFJ:LFJj;kj;lfkajs
#password is: some_pw
other_user1:
hash: JJKLJDRKJOPIQMVOIUROIJFAUROJJFIUQWKERJJFKQURJAKDJ
#password is: some_pw1
我正在尝试使用此代码删除 logstash 用户的阻止,但它没有删除它。
- name: Delete existing logstash user
blockinfile:
dest: /path_to_file/foo.yml
state: absent
block: |
logstash:
hash: $fj;kdjjfajf;ajKFJ;dfj;dkfja;dfjFJ:LFJj;kj;lfkajs
#password is: some_pw
我希望结果是:
other_user:
hash: JKJ;LKJA;LDKJF;LKJA;LKJIUR;JFKLJDQPIRQKJ;LKFJPOQJ
#password is: some_pw0
other_user1:
hash: JJKLJDRKJOPIQMVOIUROIJFAUROJJFIUQWKERJJFKQURJAKDJ
#password is: some_pw1
我错过了什么?
blockinfile
有点事。密切关注 description:
This module will insert/update/remove a block of multi-line text surrounded by customizable marker lines.
标记的默认值:# {mark} ANSIBLE MANAGED BLOCK
其中标记为 BEGIN
/END
.
因此,如果文件中没有标记,模块会将其视为未找到块。
我有一个包含以下文本块的文件。我在文本块前后都有文本
other_user:
hash: JKJ;LKJA;LDKJF;LKJA;LKJIUR;JFKLJDQPIRQKJ;LKFJPOQJ
#password is: some_pw0
logstash:
hash: $fj;kdjjfajf;ajKFJ;dfj;dkfja;dfjFJ:LFJj;kj;lfkajs
#password is: some_pw
other_user1:
hash: JJKLJDRKJOPIQMVOIUROIJFAUROJJFIUQWKERJJFKQURJAKDJ
#password is: some_pw1
我正在尝试使用此代码删除 logstash 用户的阻止,但它没有删除它。
- name: Delete existing logstash user
blockinfile:
dest: /path_to_file/foo.yml
state: absent
block: |
logstash:
hash: $fj;kdjjfajf;ajKFJ;dfj;dkfja;dfjFJ:LFJj;kj;lfkajs
#password is: some_pw
我希望结果是:
other_user:
hash: JKJ;LKJA;LDKJF;LKJA;LKJIUR;JFKLJDQPIRQKJ;LKFJPOQJ
#password is: some_pw0
other_user1:
hash: JJKLJDRKJOPIQMVOIUROIJFAUROJJFIUQWKERJJFKQURJAKDJ
#password is: some_pw1
我错过了什么?
blockinfile
有点事。密切关注 description:
This module will insert/update/remove a block of multi-line text surrounded by customizable marker lines.
标记的默认值:# {mark} ANSIBLE MANAGED BLOCK
其中标记为 BEGIN
/END
.
因此,如果文件中没有标记,模块会将其视为未找到块。