I have a playbook that copy files from different local folders to different remote paths and it works, configured to overwrite the files with backup (with copy module). How to get the list of files that will be copied and overwrite before doing it? I'd like to prevent to copy wrong files.
Example of the copy:
name: Copy all
copy:
src: scenarios/all_machines/
dest: /path/to/dest
backup: yes
force: yes
owner: root
group: root
mode: 0644
when: ansible_facts.services['crowdsec.service'] is defined
UPDATE
With this local folder:
scenarios/all_machines/
├── wg-sshd-more-logs.yaml
└── wg-x00.yaml
and this remote dir:
test_ansible/
└── wg-x00.yaml
where the wg-x00.yaml file has the same content.
With this playbook (where I changed the '>' char with '<'):
- name: TEST
synchronize:
src: scenarios/all_machines/
dest: test_ansible/
rsync_opts:
- --dry-run
register: result
- debug:
var: result.stdout_lines
- name: TEST 2
set_fact:
overwrite: "{{ file_stat|
selectattr('stat', 'match', '<f.*')|
selectattr('stat', 'ne', '<f+++++++++')|
map(attribute='file')|
list }}"
vars:
file_stat: "{{ result.stdout_lines|
map('regex_replace', regex, replace)|
map('from_yaml')|
list }}"
regex: '^(.*?) (.*)$'
replace: '{file: "\2", stat: "\1"}'
- debug:
var: overwrite
I have this output:
"result.stdout_lines": [
".d..tp..... ./",
"<f+++++++++ wg-sshd-more-logs.yaml",
"<f..tp..... wg-x00.yaml"
]
"overwrite": [
"wg-x00.yaml"
]
So:
- I changed the the '>' char with '<' because my output is different from your
- The overwrite variable tells me that the file will be overwritten but they are equal...