| 1 |
- name: Create append_newline test file |
| 2 |
copy: |
| 3 |
dest: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 4 |
content: | |
| 5 |
line1 |
| 6 |
line2 |
| 7 |
line3 |
| 8 |
|
| 9 |
- name: add content to file appending a new line |
| 10 |
blockinfile: |
| 11 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 12 |
append_newline: true |
| 13 |
insertafter: "line1" |
| 14 |
block: | |
| 15 |
line1.5 |
| 16 |
register: insert_appending_a_new_line |
| 17 |
|
| 18 |
- name: add content to file appending a new line (again) |
| 19 |
blockinfile: |
| 20 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 21 |
append_newline: true |
| 22 |
insertafter: "line1" |
| 23 |
block: | |
| 24 |
line1.5 |
| 25 |
register: insert_appending_a_new_line_again |
| 26 |
|
| 27 |
- name: get file content after adding content appending a new line |
| 28 |
stat: |
| 29 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 30 |
register: appended_a_new_line |
| 31 |
|
| 32 |
- name: check content is the expected one after inserting content appending a new line |
| 33 |
assert: |
| 34 |
that: |
| 35 |
- insert_appending_a_new_line is changed |
| 36 |
- insert_appending_a_new_line_again is not changed |
| 37 |
- appended_a_new_line.stat.checksum == "525ffd613a0b0eb6675e506226dc2adedf621f34" |
| 38 |
|
| 39 |
- name: add content to file without appending a new line |
| 40 |
blockinfile: |
| 41 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 42 |
marker: "#{mark} UNWRAPPED TEXT" |
| 43 |
insertafter: "line2" |
| 44 |
block: | |
| 45 |
line2.5 |
| 46 |
register: insert_without_appending_new_line |
| 47 |
|
| 48 |
- name: get file content after adding content without appending a new line |
| 49 |
stat: |
| 50 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 51 |
register: without_appending_new_line |
| 52 |
|
| 53 |
- name: check content is the expected one after inserting without appending a new line |
| 54 |
assert: |
| 55 |
that: |
| 56 |
- insert_without_appending_new_line is changed |
| 57 |
- without_appending_new_line.stat.checksum == "d5f5ed1428af50b5484a5184dc7e1afda1736646" |
| 58 |
|
| 59 |
- name: append a new line to existing block |
| 60 |
blockinfile: |
| 61 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 62 |
append_newline: true |
| 63 |
marker: "#{mark} UNWRAPPED TEXT" |
| 64 |
insertafter: "line2" |
| 65 |
block: | |
| 66 |
line2.5 |
| 67 |
register: append_new_line_to_existing_block |
| 68 |
|
| 69 |
- name: get file content after appending a line to existing block |
| 70 |
stat: |
| 71 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 72 |
register: new_line_appended |
| 73 |
|
| 74 |
- name: check content is the expected one after appending a new line to an existing block |
| 75 |
assert: |
| 76 |
that: |
| 77 |
- append_new_line_to_existing_block is changed |
| 78 |
- new_line_appended.stat.checksum == "b09dd16be73a0077027d5a324294db8a75a7b0f9" |
| 79 |
|
| 80 |
- name: add a block appending a new line at the end of the file |
| 81 |
blockinfile: |
| 82 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 83 |
append_newline: true |
| 84 |
marker: "#{mark} END OF FILE TEXT" |
| 85 |
insertafter: "line3" |
| 86 |
block: | |
| 87 |
line3.5 |
| 88 |
register: insert_appending_new_line_at_the_end_of_file |
| 89 |
|
| 90 |
- name: get file content after appending new line at the end of the file |
| 91 |
stat: |
| 92 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 93 |
register: inserted_block_appending_new_line_at_the_end_of_the_file |
| 94 |
|
| 95 |
- name: check content is the expected one after adding a block appending a new line at the end of the file |
| 96 |
assert: |
| 97 |
that: |
| 98 |
- insert_appending_new_line_at_the_end_of_file is changed |
| 99 |
- inserted_block_appending_new_line_at_the_end_of_the_file.stat.checksum == "9b90722b84d9bdda1be781cc4bd44d8979887691" |
| 100 |
|
| 101 |
|
| 102 |
- name: Removing a block with append_newline set to true does not append another line |
| 103 |
blockinfile: |
| 104 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 105 |
append_newline: true |
| 106 |
marker: "#{mark} UNWRAPPED TEXT" |
| 107 |
state: absent |
| 108 |
register: remove_block_appending_new_line |
| 109 |
|
| 110 |
- name: get file content after removing existing block appending new line |
| 111 |
stat: |
| 112 |
path: "{{ remote_tmp_dir_test }}/append_newline.txt" |
| 113 |
register: removed_block_appending_new_line |
| 114 |
|
| 115 |
- name: check content is the expected one after removing a block appending a new line |
| 116 |
assert: |
| 117 |
that: |
| 118 |
- remove_block_appending_new_line is changed |
| 119 |
- removed_block_appending_new_line.stat.checksum == "9a40d4c0969255cd6147537b38309d69a9b10049" |