blob: daec03627cddb673d53f4f03ac103d6a0ec88fdc (
plain)
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
|
# file module tests for dealing with modification_time
- name: Initialize the test output dir
import_tasks: initialize.yml
- name: Setup the modification time for the tests
set_fact:
modification_timestamp: "202202081414.00"
- name: Get stat info for the file
stat:
path: "{{ output_file }}"
register: initial_file_stat
- name: Set a modification time in check_mode
ansible.builtin.file:
path: "{{ output_file }}"
modification_time: "{{ modification_timestamp }}"
modification_time_format: "%Y%m%d%H%M.%S"
check_mode: true
register: file_change_check_mode
- name: Re-stat the file
stat:
path: "{{ output_file }}"
register: check_mode_stat
- name: Confirm check_mode did not change the file
assert:
that:
- initial_file_stat.stat.mtime == check_mode_stat.stat.mtime
# Ensure the changed flag was set
- file_change_check_mode.changed
# Ensure the diff is present
# Note: file diff always contains the path
- file_change_check_mode.diff.after | length > 1
- name: Set a modification time for real
ansible.builtin.file:
path: "{{ output_file }}"
modification_time: "{{ modification_timestamp }}"
modification_time_format: "%Y%m%d%H%M.%S"
register: file_change_no_check_mode
- name: Stat of the file after the change
stat:
path: "{{ output_file }}"
register: change_stat
- name: Confirm the modification time changed
assert:
that:
- initial_file_stat.stat.mtime != change_stat.stat.mtime
- file_change_no_check_mode.changed
# Note: file diff always contains the path
- file_change_no_check_mode.diff.after | length > 1
- name: Set a modification time a second time to confirm no changes or diffs
ansible.builtin.file:
path: "{{ output_file }}"
modification_time: "{{ modification_timestamp }}"
modification_time_format: "%Y%m%d%H%M.%S"
register: file_change_no_check_mode_second
- name: Confirm no changes made registered
assert:
that:
- not file_change_no_check_mode_second.changed
# Note: file diff always contains the path
- file_change_no_check_mode_second.diff.after | length == 1
|