From 49a6af1378c6d70c265c93fb610cd10454b2b7e0 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 15 Sep 2014 12:35:49 -0700 Subject: [PATCH] Test that file touch does not keep a new file if we failed to set its attributes --- .../roles/test_file/tasks/main.yml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/integration/roles/test_file/tasks/main.yml b/test/integration/roles/test_file/tasks/main.yml index 7c8262c27da..775c173f34f 100644 --- a/test/integration/roles/test_file/tasks/main.yml +++ b/test/integration/roles/test_file/tasks/main.yml @@ -65,6 +65,29 @@ - name: change ownership and group file: path={{output_dir}}/baz.txt owner=1234 group=1234 +- name: setup a tmp-like directory for ownership test + file: path=/tmp/worldwritable mode=1777 state=directory + +- name: Ask to create a file without enough perms to change ownership + file: path=/tmp/worldwritable/baz.txt state=touch owner=root + sudo: yes + sudo_user: nobody + register: chown_result + ignore_errors: True + +- name: Ask whether the new file exists + stat: path=/tmp/worldwritable/baz.txt + register: file_exists_result + +- name: Verify that the file doesn't exist on failure + assert: + that: + - "chown_result.failed == True" + - "file_exists_result.stat.exists == False" + +- name: clean up + file: path=/tmp/worldwritable state=absent + - name: create soft link to file file: src={{output_file}} dest={{output_dir}}/soft.txt state=link register: file5_result