Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
021ae05f
Commit
021ae05f
authored
Feb 20, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new test for the lineinfile module
parent
21578800
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
237 additions
and
0 deletions
+237
-0
tests_new/integration/non_destructive.yml
+1
-0
tests_new/integration/roles/test_lineinfile/files/test.txt
+5
-0
tests_new/integration/roles/test_lineinfile/meta/main.yml
+20
-0
tests_new/integration/roles/test_lineinfile/tasks/main.yml
+211
-0
No files found.
tests_new/integration/non_destructive.yml
View file @
021ae05f
...
@@ -21,4 +21,5 @@
...
@@ -21,4 +21,5 @@
-
{
role
:
test_hg
,
tags
:
test_hg
}
-
{
role
:
test_hg
,
tags
:
test_hg
}
-
{
role
:
test_changed_when
,
tags
:
test_changed_when
}
-
{
role
:
test_changed_when
,
tags
:
test_changed_when
}
-
{
role
:
test_var_blending
,
parameterized_beats_default
:
1234
,
tags
:
test_var_blending
}
-
{
role
:
test_var_blending
,
parameterized_beats_default
:
1234
,
tags
:
test_var_blending
}
-
{
role
:
test_lineinfile
,
tags
:
test_lineinfile
}
tests_new/integration/roles/test_lineinfile/files/test.txt
0 → 100644
View file @
021ae05f
This is line 1
This is line 2
REF this is a line for backrefs REF
This is line 4
This is line 5
tests_new/integration/roles/test_lineinfile/meta/main.yml
0 → 100644
View file @
021ae05f
# test code for the lineinfile module
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
dependencies
:
-
prepare_tests
tests_new/integration/roles/test_lineinfile/tasks/main.yml
0 → 100644
View file @
021ae05f
# test code for the lineinfile module
# (c) 2014, James Cammarata <jcammarata@ansible.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-
name
:
deploy the test file for lineinfile
copy
:
src=test.txt dest={{output_dir}}/test.txt
register
:
result
-
name
:
assert that the test file was deployed
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.md5sum
==
'6be7fb7fa7fb758c80a6dc0722979c40'"
-
"
result.state
==
'file'"
-
name
:
insert a line at the beginning of the file, and back it up
lineinfile
:
dest={{output_dir}}/test.txt state=present line="New line at the beginning" insertbefore="BOF" backup=yes
register
:
result
-
name
:
assert that the line was inserted at the head of the file
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
"
result.backup
!=
''"
-
name
:
stat the backup file
stat
:
path={{result.backup}}
register
:
result
-
name
:
assert the backup file matches the previous md5
assert
:
that
:
-
"
result.stat.md5
==
'6be7fb7fa7fb758c80a6dc0722979c40'"
-
name
:
stat the test after the insert at the head
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after the insert at the head
assert
:
that
:
-
"
result.stat.md5
==
'07c16434644a2a3cc1807c685917443a'"
-
name
:
insert a line at the end of the file
lineinfile
:
dest={{output_dir}}/test.txt state=present line="New line at the end" insertafter="EOF"
register
:
result
-
name
:
assert that the line was inserted at the end of the file
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
name
:
stat the test after the insert at the end
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after the insert at the end
assert
:
that
:
-
"
result.stat.md5
==
'da4c2150e5782fcede1840280ab87eff'"
-
name
:
insert a line after the first line
lineinfile
:
dest={{output_dir}}/test.txt state=present line="New line after line 1" insertafter="^This is line 1$"
register
:
result
-
name
:
assert that the line was inserted after the first line
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
name
:
stat the test after insert after the first line
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after the insert after the first line
assert
:
that
:
-
"
result.stat.md5
==
'196722c8faaa28b960bee66fa4cce58c'"
-
name
:
insert a line before the last line
lineinfile
:
dest={{output_dir}}/test.txt state=present line="New line after line 5" insertbefore="^This is line 5$"
register
:
result
-
name
:
assert that the line was inserted before the last line
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
name
:
stat the test after the insert before the last line
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after the insert before the last line
assert
:
that
:
-
"
result.stat.md5
==
'd5955ee042139dfef16dbe3a7334475f'"
-
name
:
replace a line with backrefs
lineinfile
:
dest={{output_dir}}/test.txt state=present line="This is line 3" backrefs=yes regexp="^(REF) .* \1$"
register
:
result
-
name
:
assert that the line with backrefs was changed
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
replaced'"
-
name
:
stat the test after the backref line was replaced
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after backref line was replaced
assert
:
that
:
-
"
result.stat.md5
==
'0f585270054e17be242743dd31c6f593'"
-
name
:
remove the middle line
lineinfile
:
dest={{output_dir}}/test.txt state=absent regexp="^This is line 3$"
register
:
result
-
name
:
assert that the line was inserted at the head of the file
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'1
line(s)
removed'"
-
name
:
stat the test after the middle line was removed
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after the middle line was removed
assert
:
that
:
-
"
result.stat.md5
==
'661603660051991b79429c2dc68d9a67'"
-
name
:
run a validation script that succeeds
lineinfile
:
dest={{output_dir}}/test.txt state=absent regexp="^This is line 5$" validate="/bin/true %s"
register
:
result
-
name
:
assert that the file validated after removing a line
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'1
line(s)
removed'"
-
name
:
stat the test after the validation succeeded
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after the validation succeeded
assert
:
that
:
-
"
result.stat.md5
==
'9af984939bd859f7794661e501b4f1a4'"
-
name
:
run a validation script that fails
lineinfile
:
dest={{output_dir}}/test.txt state=absent regexp="^This is line 1$" validate="/bin/false %s"
register
:
result
ignore_errors
:
yes
-
name
:
assert that the validate failed
assert
:
that
:
-
"
result.failed
==
true"
-
name
:
stat the test after the validation failed
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches the previous after the validation failed
assert
:
that
:
-
"
result.stat.md5
==
'9af984939bd859f7794661e501b4f1a4'"
-
name
:
use create=yes
lineinfile
:
dest={{output_dir}}/new_test.txt create=yes insertbefore=BOF state=present line="This is a new file"
register
:
result
-
name
:
assert that the new file was created
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
name
:
validate that the newly created file exists
stat
:
path={{output_dir}}/new_test.txt
register
:
result
ignore_errors
:
yes
-
name
:
assert the newly created test md5 matches
assert
:
that
:
-
"
result.stat.md5
==
'fef1d487711facfd7aa2c87d788c19d9'"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment