Debian Codegraph @

test/integration/targets/template/tasks/backup_test.yml

raw
1 # https://github.com/ansible/ansible/issues/24408
2
3 - set_fact:
4 t_username: templateuser1
5 t_groupname: templateuser1
6
7 - name: create the test group
8 group:
9 name: "{{ t_groupname }}"
10
11 - name: create the test user
12 user:
13 name: "{{ t_username }}"
14 group: "{{ t_groupname }}"
15 createhome: no
16
17 - name: set the dest file
18 set_fact:
19 t_dest: "{{ output_dir + '/tfile_dest.txt' }}"
20
21 - name: create the old file
22 file:
23 path: "{{ t_dest }}"
24 state: touch
25 mode: 0777
26 owner: "{{ t_username }}"
27 group: "{{ t_groupname }}"
28
29 - name: failsafe attr change in case underlying system does not support it
30 shell: chattr =j "{{ t_dest }}"
31 ignore_errors: True
32
33 - name: run the template
34 template:
35 src: foo.j2
36 dest: "{{ t_dest }}"
37 backup: True
38 register: t_backup_res
39
40 - name: check the data for the backup
41 stat:
42 path: "{{ t_backup_res.backup_file }}"
43 register: t_backup_stats
44
45 - name: validate result of preserved backup
46 assert:
47 that:
48 - 't_backup_stats.stat.mode == "0777"'
49 - 't_backup_stats.stat.pw_name == t_username'
50 - 't_backup_stats.stat.gr_name == t_groupname'
51
52 - name: cleanup the user
53 user:
54 name: "{{ t_username }}"
55 state: absent
56
57 - name: cleanup the group
58 user:
59 name: "{{ t_groupname }}"
60 state: absent