| 1 |
- name: Create prepend_newline test file |
| 2 |
copy: |
| 3 |
dest: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 4 |
content: | |
| 5 |
line1 |
| 6 |
line2 |
| 7 |
line3 |
| 8 |
|
| 9 |
- name: add content to file prepending a new line at the beginning of the file |
| 10 |
blockinfile: |
| 11 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 12 |
prepend_newline: true |
| 13 |
insertbefore: "line1" |
| 14 |
block: | |
| 15 |
line0.5 |
| 16 |
register: insert_prepending_a_new_line_at_the_beginning_of_the_file |
| 17 |
|
| 18 |
- name: get file content after adding content prepending a new line at the beginning of the file |
| 19 |
stat: |
| 20 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 21 |
register: prepended_a_new_line_at_the_beginning_of_the_file |
| 22 |
|
| 23 |
- name: check content is the expected one after prepending a new line at the beginning of the file |
| 24 |
assert: |
| 25 |
that: |
| 26 |
- insert_prepending_a_new_line_at_the_beginning_of_the_file is changed |
| 27 |
- prepended_a_new_line_at_the_beginning_of_the_file.stat.checksum == "bfd32c880bbfadd1983c67836c46bf8ed9d50343" |
| 28 |
|
| 29 |
- name: add content to file prepending a new line |
| 30 |
blockinfile: |
| 31 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 32 |
prepend_newline: true |
| 33 |
marker: "#{mark} WRAPPED TEXT" |
| 34 |
insertafter: "line1" |
| 35 |
block: | |
| 36 |
line1.5 |
| 37 |
register: insert_prepending_a_new_line |
| 38 |
|
| 39 |
- name: add content to file prepending a new line (again) |
| 40 |
blockinfile: |
| 41 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 42 |
prepend_newline: true |
| 43 |
marker: "#{mark} WRAPPED TEXT" |
| 44 |
insertafter: "line1" |
| 45 |
block: | |
| 46 |
line1.5 |
| 47 |
register: insert_prepending_a_new_line_again |
| 48 |
|
| 49 |
- name: get file content after adding content prepending a new line |
| 50 |
stat: |
| 51 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 52 |
register: prepended_a_new_line |
| 53 |
|
| 54 |
- name: check content is the expected one after inserting content prepending a new line |
| 55 |
assert: |
| 56 |
that: |
| 57 |
- insert_prepending_a_new_line is changed |
| 58 |
- insert_prepending_a_new_line_again is not changed |
| 59 |
- prepended_a_new_line.stat.checksum == "d5b8b42690f4a38b9a040adc3240a6f81ad5f8ee" |
| 60 |
|
| 61 |
- name: add content to file without prepending a new line |
| 62 |
blockinfile: |
| 63 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 64 |
marker: "#{mark} UNWRAPPED TEXT" |
| 65 |
insertafter: "line3" |
| 66 |
block: | |
| 67 |
line3.5 |
| 68 |
register: insert_without_prepending_new_line |
| 69 |
|
| 70 |
- name: get file content after adding content without prepending a new line |
| 71 |
stat: |
| 72 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 73 |
register: without_prepending_new_line |
| 74 |
|
| 75 |
- name: check content is the expected one after inserting without prepending a new line |
| 76 |
assert: |
| 77 |
that: |
| 78 |
- insert_without_prepending_new_line is changed |
| 79 |
- without_prepending_new_line.stat.checksum == "ad06200e7ee5b22b7eff4c57075b42d038eaffb6" |
| 80 |
|
| 81 |
- name: prepend a new line to existing block |
| 82 |
blockinfile: |
| 83 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 84 |
prepend_newline: true |
| 85 |
marker: "#{mark} UNWRAPPED TEXT" |
| 86 |
insertafter: "line3" |
| 87 |
block: | |
| 88 |
line3.5 |
| 89 |
register: prepend_new_line_to_existing_block |
| 90 |
|
| 91 |
- name: get file content after prepending a new line to an existing block |
| 92 |
stat: |
| 93 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 94 |
register: new_line_prepended |
| 95 |
|
| 96 |
- name: check content is the expected one after prepending a new line to an existing block |
| 97 |
assert: |
| 98 |
that: |
| 99 |
- prepend_new_line_to_existing_block is changed |
| 100 |
- new_line_prepended.stat.checksum == "f2dd48160fb3c7c8e02d292666a1a3f08503f6bf" |
| 101 |
|
| 102 |
- name: Removing a block with prepend_newline set to true does not prepend another line |
| 103 |
blockinfile: |
| 104 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 105 |
prepend_newline: true |
| 106 |
marker: "#{mark} UNWRAPPED TEXT" |
| 107 |
state: absent |
| 108 |
register: remove_block_prepending_new_line |
| 109 |
|
| 110 |
- name: get file content after removing existing block prepending new line |
| 111 |
stat: |
| 112 |
path: "{{ remote_tmp_dir_test }}/prepend_newline.txt" |
| 113 |
register: removed_block_prepending_new_line |
| 114 |
|
| 115 |
- name: check content is the expected one after removing a block prepending a new line |
| 116 |
assert: |
| 117 |
that: |
| 118 |
- remove_block_prepending_new_line is changed |
| 119 |
- removed_block_prepending_new_line.stat.checksum == "c97c3da7d607acfd5d786fbb81f3d93d867c914a" |