2014-02-14 00:28:29 +01:00
|
|
|
# test code for the copy module and action plugin
|
|
|
|
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.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/>.
|
|
|
|
|
2014-02-19 20:17:03 +01:00
|
|
|
- name: record the output directory
|
|
|
|
set_fact: output_file={{output_dir}}/foo.txt
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
- name: initiate a basic copy
|
|
|
|
copy: src=foo.txt dest={{output_file}}
|
|
|
|
register: copy_result
|
|
|
|
|
2014-02-19 20:05:03 +01:00
|
|
|
- name: assert basic copy worked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'changed' in copy_result"
|
|
|
|
- "'dest' in copy_result"
|
|
|
|
- "'group' in copy_result"
|
|
|
|
- "'gid' in copy_result"
|
|
|
|
- "'md5sum' in copy_result"
|
|
|
|
- "'owner' in copy_result"
|
|
|
|
- "'size' in copy_result"
|
|
|
|
- "'src' in copy_result"
|
|
|
|
- "'state' in copy_result"
|
|
|
|
- "'uid' in copy_result"
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
2014-02-19 20:17:03 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "copy_result.changed == true"
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
- name: verify that the file md5sum is correct
|
2014-02-19 20:17:03 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "copy_result.md5sum == 'c47397529fe81ab62ba3f85e9f4c71f2'"
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
- name: check the stat results of the file
|
|
|
|
stat: path={{output_file}}
|
|
|
|
register: stat_results
|
|
|
|
|
|
|
|
- debug: var=stat_results
|
|
|
|
|
2014-02-19 20:17:03 +01:00
|
|
|
- name: assert the stat results are correct
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "stat_results.stat.exists == true"
|
|
|
|
- "stat_results.stat.isblk == false"
|
|
|
|
- "stat_results.stat.isfifo == false"
|
|
|
|
- "stat_results.stat.isreg == true"
|
|
|
|
- "stat_results.stat.issock == false"
|
|
|
|
- "stat_results.stat.md5 == 'c47397529fe81ab62ba3f85e9f4c71f2'"
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
- name: overwrite the file via same means
|
|
|
|
copy: src=foo.txt dest={{output_file}}
|
|
|
|
register: copy_result2
|
|
|
|
|
2014-02-19 20:17:03 +01:00
|
|
|
- name: assert that the file was not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not copy_result2|changed"
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
- name: overwrite the file using the content system
|
|
|
|
copy: content="modified" dest={{output_file}}
|
|
|
|
register: copy_result3
|
|
|
|
|
2014-02-19 20:17:03 +01:00
|
|
|
- name: assert that the file has changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "copy_result3|changed"
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
- name: overwrite the file again using the content system
|
|
|
|
copy: content="modified" dest={{output_file}}
|
|
|
|
register: copy_result4
|
|
|
|
|
2014-02-19 20:17:03 +01:00
|
|
|
- name: assert that the copy result has not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not copy_result4|changed"
|
2014-02-14 00:28:29 +01:00
|
|
|
|
|
|
|
# TODO: test recursive copy
|
|
|
|
# TODO: test copy where destination is a directory like {{output_dir}}/
|
|
|
|
# TODO: test that copy fails if the path does not exist
|
|
|
|
# TODO: ...
|
|
|
|
|
|
|
|
|