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 actualy 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      # TODO: This is a legitimate bug
117      #- not check_mode_trailing_slash_first_stat.stat.exists
118      - check_mode_trailing_slash_real is changed
119      - check_mode_trailing_slash_real_stat.stat.exists
120      - check_mode_trailing_slash_second is not changed
121
122      - check_mode_foo_first is changed
123      - not check_mode_foo_first_stat.stat.exists
124      - check_mode_foo_real is changed
125      - check_mode_foo_real_stat.stat.exists
126      - check_mode_foo_second is not changed
127