mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-09 06:40:03 -07:00
Skip if insertbefore BOF until later (#41767)
If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF. Add tests for this scenario.
This commit is contained in:
parent
93537425a0
commit
eaae1318f8
2 changed files with 18 additions and 10 deletions
|
@ -36,18 +36,27 @@
|
|||
line: "New line at the beginning"
|
||||
insertbefore: "BOF"
|
||||
backup: yes
|
||||
register: result
|
||||
register: result1
|
||||
|
||||
- name: insert a line at the beginning of the file again
|
||||
lineinfile:
|
||||
dest: "{{ output_dir }}/test.txt"
|
||||
state: present
|
||||
line: "New line at the beginning"
|
||||
insertbefore: "BOF"
|
||||
register: result2
|
||||
|
||||
- name: assert that the line was inserted at the head of the file
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- "result.msg == 'line added'"
|
||||
- "result.backup != ''"
|
||||
- result1 is changed
|
||||
- result2 is not changed
|
||||
- result1.msg == 'line added'
|
||||
- result1.backup != ''
|
||||
|
||||
- name: stat the backup file
|
||||
stat:
|
||||
path: "{{ result.backup }}"
|
||||
path: "{{ result1.backup }}"
|
||||
register: result
|
||||
|
||||
- name: assert the backup file matches the previous hash
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue