| 1 |
- block: |
| 2 |
|
| 3 |
- name: check_mode - Create another clean copy of 'subdir' not messed with by previous tests (check_mode) |
| 4 |
copy: |
| 5 |
src: subdir |
| 6 |
dest: 'checkmode_subdir/' |
| 7 |
directory_mode: 0700 |
| 8 |
local_follow: False |
| 9 |
check_mode: true |
| 10 |
register: check_mode_subdir_first |
| 11 |
|
| 12 |
- name: check_mode - Stat the new dir to make sure it really doesn't exist |
| 13 |
stat: |
| 14 |
path: 'checkmode_subdir/' |
| 15 |
register: check_mode_subdir_first_stat |
| 16 |
|
| 17 |
- name: check_mode - Actually do it |
| 18 |
copy: |
| 19 |
src: subdir |
| 20 |
dest: 'checkmode_subdir/' |
| 21 |
directory_mode: 0700 |
| 22 |
local_follow: False |
| 23 |
register: check_mode_subdir_real |
| 24 |
|
| 25 |
- name: check_mode - Stat the new dir to make sure it really exists |
| 26 |
stat: |
| 27 |
path: 'checkmode_subdir/' |
| 28 |
register: check_mode_subdir_real_stat |
| 29 |
|
| 30 |
# Quick sanity before we move on |
| 31 |
- assert: |
| 32 |
that: |
| 33 |
- check_mode_subdir_first is changed |
| 34 |
- not check_mode_subdir_first_stat.stat.exists |
| 35 |
- check_mode_subdir_real is changed |
| 36 |
- check_mode_subdir_real_stat.stat.exists |
| 37 |
|
| 38 |
# Do some finagling here. First, use check_mode to ensure it never gets |
| 39 |
# created. Then actually create it, and use check_mode to ensure that doing |
| 40 |
# the same copy gets marked as no change. |
| 41 |
# |
| 42 |
# This same pattern repeats for several other src/dest combinations. |
| 43 |
- name: check_mode - Ensure dest with trailing / never gets created but would be without check_mode |
| 44 |
copy: |
| 45 |
remote_src: true |
| 46 |
src: 'checkmode_subdir/' |
| 47 |
dest: 'destdir_should_never_exist_because_of_check_mode/' |
| 48 |
follow: true |
| 49 |
check_mode: true |
| 50 |
register: check_mode_trailing_slash_first |
| 51 |
|
| 52 |
- name: check_mode - Stat the new dir to make sure it really doesn't exist |
| 53 |
stat: |
| 54 |
path: 'destdir_should_never_exist_because_of_check_mode/' |
| 55 |
register: check_mode_trailing_slash_first_stat |
| 56 |
|
| 57 |
- name: check_mode - Create the above copy for real now (without check_mode) |
| 58 |
copy: |
| 59 |
remote_src: true |
| 60 |
src: 'checkmode_subdir/' |
| 61 |
dest: 'destdir_should_never_exist_because_of_check_mode/' |
| 62 |
register: check_mode_trailing_slash_real |
| 63 |
|
| 64 |
- name: check_mode - Stat the new dir to make sure it really exists |
| 65 |
stat: |
| 66 |
path: 'destdir_should_never_exist_because_of_check_mode/' |
| 67 |
register: check_mode_trailing_slash_real_stat |
| 68 |
|
| 69 |
- name: check_mode - Do the same copy yet again (with check_mode this time) to ensure it's marked unchanged |
| 70 |
copy: |
| 71 |
remote_src: true |
| 72 |
src: 'checkmode_subdir/' |
| 73 |
dest: 'destdir_should_never_exist_because_of_check_mode/' |
| 74 |
check_mode: true |
| 75 |
register: check_mode_trailing_slash_second |
| 76 |
|
| 77 |
# Repeat the same basic pattern here. |
| 78 |
|
| 79 |
- name: check_mode - Do another basic copy (with check_mode) |
| 80 |
copy: |
| 81 |
src: foo.txt |
| 82 |
dest: "{{ remote_dir }}/foo-check_mode.txt" |
| 83 |
mode: 0444 |
| 84 |
check_mode: true |
| 85 |
register: check_mode_foo_first |
| 86 |
|
| 87 |
- name: check_mode - Stat the new file to make sure it really doesn't exist |
| 88 |
stat: |
| 89 |
path: "{{ remote_dir }}/foo-check_mode.txt" |
| 90 |
register: check_mode_foo_first_stat |
| 91 |
|
| 92 |
- name: check_mode - Do the same basic copy (without check_mode) |
| 93 |
copy: |
| 94 |
src: foo.txt |
| 95 |
dest: "{{ remote_dir }}/foo-check_mode.txt" |
| 96 |
mode: 0444 |
| 97 |
register: check_mode_foo_real |
| 98 |
|
| 99 |
- name: check_mode - Stat the new file to make sure it really exists |
| 100 |
stat: |
| 101 |
path: "{{ remote_dir }}/foo-check_mode.txt" |
| 102 |
register: check_mode_foo_real_stat |
| 103 |
|
| 104 |
- name: check_mode - And again (with check_mode) |
| 105 |
copy: |
| 106 |
src: foo.txt |
| 107 |
dest: "{{ remote_dir }}/foo-check_mode.txt" |
| 108 |
mode: 0444 |
| 109 |
register: check_mode_foo_second |
| 110 |
|
| 111 |
- assert: |
| 112 |
that: |
| 113 |
- check_mode_subdir_first is changed |
| 114 |
|
| 115 |
- check_mode_trailing_slash_first is changed |
| 116 |
- not check_mode_trailing_slash_first_stat.stat.exists |
| 117 |
- check_mode_trailing_slash_real is changed |
| 118 |
- check_mode_trailing_slash_real_stat.stat.exists |
| 119 |
- check_mode_trailing_slash_second is not changed |
| 120 |
|
| 121 |
- check_mode_foo_first is changed |
| 122 |
- not check_mode_foo_first_stat.stat.exists |
| 123 |
- check_mode_foo_real is changed |
| 124 |
- check_mode_foo_real_stat.stat.exists |
| 125 |
- check_mode_foo_second is not changed |
| 126 |
|
| 127 |
- name: check_mode - Do a basic copy to setup next test (without check mode) |
| 128 |
copy: |
| 129 |
src: foo.txt |
| 130 |
dest: "{{ remote_dir }}/foo-check_mode.txt" |
| 131 |
mode: 0444 |
| 132 |
|
| 133 |
- name: check_mode - Copy the same src with a different mode (check mode) |
| 134 |
copy: |
| 135 |
src: foo.txt |
| 136 |
dest: "{{ remote_dir }}/foo-check_mode.txt" |
| 137 |
mode: 0666 |
| 138 |
check_mode: True |
| 139 |
register: check_mode_file_attribute |
| 140 |
|
| 141 |
- name: stat the file to make sure the mode was not updated in check mode |
| 142 |
stat: |
| 143 |
path: "{{ remote_dir }}/foo-check_mode.txt" |
| 144 |
register: check_mode_file_attribute_stat |
| 145 |
|
| 146 |
- name: check_mode - Copy the same src with a different mode (without check mode) |
| 147 |
copy: |
| 148 |
src: foo.txt |
| 149 |
dest: "{{ remote_dir }}/foo-check_mode.txt" |
| 150 |
mode: 0666 |
| 151 |
register: real_file_attribute |
| 152 |
|
| 153 |
- name: stat the file to make sure the mode was updated without check mode |
| 154 |
stat: |
| 155 |
path: "{{ remote_dir }}/foo-check_mode.txt" |
| 156 |
register: real_file_attribute_stat |
| 157 |
|
| 158 |
- assert: |
| 159 |
that: |
| 160 |
- check_mode_file_attribute is changed |
| 161 |
- real_file_attribute is changed |
| 162 |
- "check_mode_file_attribute_stat.stat.mode == '0444'" |
| 163 |
- "real_file_attribute_stat.stat.mode == '0666'" |