summaryrefslogtreecommitdiff
path: root/test/integration/targets/blockinfile/tasks
diff options
context:
space:
mode:
authorSam Doran <sdoran@redhat.com>2018-09-28 16:04:50 -0400
committerGitHub <noreply@github.com>2018-09-28 16:04:50 -0400
commit8b1ae30e2ee86cdb8b68944b94846bbaf46228b4 (patch)
tree155e2454efd6972792d43bf387eb31bffe2308ac /test/integration/targets/blockinfile/tasks
parent2d01966e87a20e004af41af3dbca59426ae51c17 (diff)
downloadansible-8b1ae30e2ee86cdb8b68944b94846bbaf46228b4.tar.gz
Use bytes rather than native string for result (#46281)
This prevents a stack trace in Python 3 when the result is an empty file since the file is open in binary mode and a native string in Python 3 is str, not bytes.
Diffstat (limited to 'test/integration/targets/blockinfile/tasks')
-rw-r--r--test/integration/targets/blockinfile/tasks/main.yml93
1 files changed, 70 insertions, 23 deletions
diff --git a/test/integration/targets/blockinfile/tasks/main.yml b/test/integration/targets/blockinfile/tasks/main.yml
index e1a17d358d..86e066d944 100644
--- a/test/integration/targets/blockinfile/tasks/main.yml
+++ b/test/integration/targets/blockinfile/tasks/main.yml
@@ -16,13 +16,18 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-- set_fact: output_dir_test={{output_dir}}/test_blockinfile
+- set_fact:
+ output_dir_test: "{{ output_dir }}/test_blockinfile"
- name: make sure our testing sub-directory does not exist
- file: path="{{ output_dir_test }}" state=absent
+ file:
+ path: "{{ output_dir_test }}"
+ state: absent
- name: create our testing sub-directory
- file: path="{{ output_dir_test }}" state=directory
+ file:
+ path: "{{ output_dir_test }}"
+ state: directory
##
## blockinfile
@@ -30,38 +35,80 @@
- name: copy the sshd_config to the test dir
copy:
- src: sshd_config
- dest: "{{ output_dir_test }}"
+ src: sshd_config
+ dest: "{{ output_dir_test }}"
- name: insert/update "Match User" configuration block in sshd_config
blockinfile:
- path: "{{ output_dir_test }}/sshd_config"
- block: |
- Match User ansible-agent
- PasswordAuthentication no
+ path: "{{ output_dir_test }}/sshd_config"
+ block: |
+ Match User ansible-agent
+ PasswordAuthentication no
register: blockinfile_test0
+
- name: check content
shell: 'grep -e "Match User ansible-agent" -e "PasswordAuthentication no" {{ output_dir_test }}/sshd_config'
register: blockinfile_test0_grep
-- debug: var=blockinfile_test0
-- debug: var=blockinfile_test0_grep
+
+- debug:
+ var: blockinfile_test0
+ verbosity: 1
+
+- debug:
+ var: blockinfile_test0_grep
+ verbosity: 1
+
- name: validate first example results
assert:
- that:
- - 'blockinfile_test0.changed is defined'
- - 'blockinfile_test0.msg is defined'
- - 'blockinfile_test0.changed'
- - 'blockinfile_test0.msg == "Block inserted"'
- - 'blockinfile_test0_grep.stdout_lines | length == 2'
+ that:
+ - 'blockinfile_test0.changed is defined'
+ - 'blockinfile_test0.msg is defined'
+ - 'blockinfile_test0.changed'
+ - 'blockinfile_test0.msg == "Block inserted"'
+ - 'blockinfile_test0_grep.stdout_lines | length == 2'
- name: check idemptotence
blockinfile:
- path: "{{ output_dir_test }}/sshd_config"
- block: |
- Match User ansible-agent
- PasswordAuthentication no
+ path: "{{ output_dir_test }}/sshd_config"
+ block: |
+ Match User ansible-agent
+ PasswordAuthentication no
register: blockinfile_test1
+
- name: validate idempotence results
assert:
- that:
- - 'not blockinfile_test1.changed'
+ that:
+ - 'not blockinfile_test1.changed'
+
+- name: Create a file with blockinfile
+ blockinfile:
+ path: "{{ output_dir_test }}/empty.txt"
+ block: |
+ Hey
+ there
+ state: present
+ create: yes
+ register: empty_test_1
+
+- name: Run a task that results in an empty file
+ blockinfile:
+ path: "{{ output_dir_test }}/empty.txt"
+ block: |
+ Hey
+ there
+ state: absent
+ create: yes
+ register: empty_test_2
+
+- stat:
+ path: "{{ output_dir_test }}/empty.txt"
+ register: empty_test_stat
+
+- name: Ensure empty file was created
+ assert:
+ that:
+ - empty_test_1 is changed
+ - "'File created' in empty_test_1.msg"
+ - empty_test_2 is changed
+ - "'Block removed' in empty_test_2.msg"
+ - empty_test_stat.stat.size == 0