Debian Codegraph @

test/integration/targets/file/tasks/modification_time.yml

raw
1 # file module tests for dealing with modification_time
2
3 - name: Initialize the test output dir
4 import_tasks: initialize.yml
5
6 - name: Setup the modification time for the tests
7 set_fact:
8 modification_timestamp: "202202081414.00"
9
10 - name: Get stat info for the file
11 stat:
12 path: "{{ output_file }}"
13 register: initial_file_stat
14
15 - name: Set a modification time in check_mode
16 ansible.builtin.file:
17 path: "{{ output_file }}"
18 modification_time: "{{ modification_timestamp }}"
19 modification_time_format: "%Y%m%d%H%M.%S"
20 check_mode: true
21 register: file_change_check_mode
22 diff: true
23
24 - name: Re-stat the file
25 stat:
26 path: "{{ output_file }}"
27 register: check_mode_stat
28
29 - name: Confirm check_mode did not change the file
30 assert:
31 that:
32 - initial_file_stat.stat.mtime == check_mode_stat.stat.mtime
33 # Ensure the changed flag was set
34 - file_change_check_mode.changed
35 # Ensure the diff is present
36 # Note: file diff always contains the path
37 - file_change_check_mode.diff.after | length > 1
38
39 - name: Set a modification time for real
40 ansible.builtin.file:
41 path: "{{ output_file }}"
42 modification_time: "{{ modification_timestamp }}"
43 modification_time_format: "%Y%m%d%H%M.%S"
44 register: file_change_no_check_mode
45 diff: true
46
47 - name: Stat of the file after the change
48 stat:
49 path: "{{ output_file }}"
50 register: change_stat
51
52 - name: Confirm the modification time changed
53 assert:
54 that:
55 - initial_file_stat.stat.mtime != change_stat.stat.mtime
56 - file_change_no_check_mode.changed
57 # Note: file diff always contains the path
58 - file_change_no_check_mode.diff.after | length > 1
59
60 - name: Set a modification time a second time to confirm no changes or diffs
61 ansible.builtin.file:
62 path: "{{ output_file }}"
63 modification_time: "{{ modification_timestamp }}"
64 modification_time_format: "%Y%m%d%H%M.%S"
65 register: file_change_no_check_mode_second
66 diff: true
67
68 - name: Confirm no changes made registered
69 assert:
70 that:
71 - not file_change_no_check_mode_second.changed
72 # Note: file diff always contains the path
73 - file_change_no_check_mode_second.diff.after | length == 1