Skip to content

Commit

Permalink
Add a new test: test-replace
Browse files Browse the repository at this point in the history
The test demonstrates a common strategy for safer blockinfilie with
insertafter.  It ensures that the pattern is at the end of line using
replace module before inserting a block in the next line of the line
with that pattern.
  • Loading branch information
yaegashi committed Apr 26, 2015
1 parent d1d0dc9 commit 64cece7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/expected/test-replace/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html><head><title>111 222 333</title></head><Body>
<!-- BEGIN ANSIBLE MANAGED BLOCK -->
<h2>aaa bbb ccc</h2>
<h2>AAA BBB CCC</h2>
<!-- END ANSIBLE MANAGED BLOCK -->
<p>!!! @@@ ###</p></body></html>
1 change: 1 addition & 0 deletions tests/fixtures/test-replace/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><head><title>111 222 333</title></head><Body><p>!!! @@@ ###</p></body></html>
21 changes: 21 additions & 0 deletions tests/test-replace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- hosts: localhost
vars:
- testing_dir: "{{playbook_dir}}/testing"
roles:
- ../..
tasks:
- name: insert a newline after <body>
replace:
dest: "{{testing_dir}}/index.html"
backup: yes
regexp: (?i)(<body>)(?=.)
replace: \1\n
- name: insert a block after <body>
blockinfile:
dest: "{{testing_dir}}/index.html"
backup: yes
marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
content: |
<h2>aaa bbb ccc</h2>
<h2>AAA BBB CCC</h2>
insertafter: (?i)<body>

0 comments on commit 64cece7

Please sign in to comment.