• name: Create archive, copy to local host and delete on remote

hosts: all

tasks:

  • name: Create archive

ansible.builtin.archive:
path: /tmp/rm/*
format: tgz
dest: /tmp/archive.tgz

  • name: Copy archive to remote host

ansible.builtin.copy:
src: /tmp/archive.tgz
dest: /tmp/down/{{ inventory_hostname }}.tgz
mode: '0644'

  • name: Delete archive on remote host

ansible.builtin.file:
path: /tmp/down/{{ inventory_hostname }}.tgz
state: absent

[file-name 000080_2025-03-27_08-56-07.txt]