Debian Codegraph @

test/integration/targets/blockinfile/tasks/preserve_line_endings.yml

raw
1 - name: create line_endings_test.txt in the test dir
2 copy:
3 dest: "{{ remote_tmp_dir_test }}/line_endings_test.txt"
4 # generating the content like this instead of copying a fixture file
5 # prevents sanity checks from warning about mixed line endings
6 content: "unix\nunix\nunix\n\ndos\r\ndos\r\ndos\r\n\nunix\nunix\n# BEGIN ANSIBLE MANAGED BLOCK\ndos\r\n# END ANSIBLE MANAGED BLOCK\nunix\nunix\nunix\nunix\n"
7
8 - name: insert/update "dos" configuration block in line_endings_test.txt
9 blockinfile:
10 path: "{{ remote_tmp_dir_test }}/line_endings_test.txt"
11 block: "dos\r\ndos\r\ndos\r\n"
12 register: blockinfile_test2
13
14 - name: check content
15 # using the more precise `grep -Pc "^dos\\r$" ...` fails on BSD/macOS
16 shell: 'grep -c "^dos.$" {{ remote_tmp_dir_test }}/line_endings_test.txt'
17 register: blockinfile_test2_grep
18
19 - name: validate line_endings_test.txt results
20 assert:
21 that:
22 - 'blockinfile_test2 is changed'
23 - 'blockinfile_test2.msg == "Block inserted"'
24 - 'blockinfile_test2_grep.stdout == "6"'