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