mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 04:24:00 -07:00
[WIP] Create preserved_copy function in basic.py to perserve file ownership. (#27344)
Create preserved_copy function in basic.py to perserve file ownership. * Add a test for template preserved backup * Use a script to get the random names * bytes to strings * Remove dump of hostvars * Stop being fancy and create a testuser instead * Fix pep8 * set file attributes * Pass the correct data to set_attributes_if_different * Use -j instead -b and pass the attributes as a string instead of a list * remove debugging message * Use shell to softly set the attr Fixes #24408
This commit is contained in:
parent
b266204afa
commit
baf1ed9100
3 changed files with 100 additions and 1 deletions
60
test/integration/targets/template/tasks/backup_test.yml
Normal file
60
test/integration/targets/template/tasks/backup_test.yml
Normal file
|
@ -0,0 +1,60 @@
|
|||
# https://github.com/ansible/ansible/issues/24408
|
||||
|
||||
- set_fact:
|
||||
t_username: templateuser1
|
||||
t_groupname: templateuser1
|
||||
|
||||
- name: create the test group
|
||||
group:
|
||||
name: "{{ t_groupname }}"
|
||||
|
||||
- name: create the test user
|
||||
user:
|
||||
name: "{{ t_username }}"
|
||||
group: "{{ t_groupname }}"
|
||||
createhome: no
|
||||
|
||||
- name: set the dest file
|
||||
set_fact:
|
||||
t_dest: "{{ output_dir + '/tfile_dest.txt' }}"
|
||||
|
||||
- name: create the old file
|
||||
file:
|
||||
path: "{{ t_dest }}"
|
||||
state: touch
|
||||
mode: 0777
|
||||
owner: "{{ t_username }}"
|
||||
group: "{{ t_groupname }}"
|
||||
|
||||
- name: failsafe attr change incase underlying system does not support it
|
||||
shell: chattr =j "{{ t_dest }}"
|
||||
ignore_errors: True
|
||||
|
||||
- name: run the template
|
||||
template:
|
||||
src: foo.j2
|
||||
dest: "{{ t_dest }}"
|
||||
backup: True
|
||||
register: t_backup_res
|
||||
|
||||
- name: check the data for the backup
|
||||
stat:
|
||||
path: "{{ t_backup_res.backup_file }}"
|
||||
register: t_backup_stats
|
||||
|
||||
- name: validate result of preserved backup
|
||||
assert:
|
||||
that:
|
||||
- 't_backup_stats.stat.mode == "0777"'
|
||||
- 't_backup_stats.stat.pw_name == t_username'
|
||||
- 't_backup_stats.stat.gr_name == t_groupname'
|
||||
|
||||
- name: cleanup the user
|
||||
user:
|
||||
name: "{{ t_username }}"
|
||||
state: absent
|
||||
|
||||
- name: cleanup the group
|
||||
user:
|
||||
name: "{{ t_groupname }}"
|
||||
state: absent
|
|
@ -369,3 +369,6 @@
|
|||
that:
|
||||
- 'diff_result.stdout == ""'
|
||||
- "diff_result.rc == 0"
|
||||
|
||||
# aliases file requires root for template tests so this should be safe
|
||||
- include: backup_test.yml
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue