Debian Codegraph @

ansible_collections/containers/podman/playbooks/examples/podman_copy_fetch.yml

raw
1 ---
2 - name: Copy files into container and fetch them back
3 hosts: all
4 gather_facts: false
5 vars:
6 ansible_connection: containers.podman.podman
7 tasks:
8 - name: Compute controller time
9 delegate_to: localhost
10 vars:
11 ansible_connection: local
12 set_fact:
13 controller_now: "{{ lookup('pipe', 'date -Is') }}"
14
15 - name: Create temp file on controller
16 delegate_to: localhost
17 vars:
18 ansible_connection: local
19 copy:
20 dest: "/tmp/hello_from_controller.txt"
21 content: "Hello from controller at {{ controller_now }}\n"
22
23 - name: Upload file to container via podman cp
24 delegate_to: localhost
25 vars:
26 ansible_connection: local
27 command: >-
28 podman cp /tmp/hello_from_controller.txt {{ inventory_hostname }}:/tmp/hello_in_container.txt
29
30 - name: Show file details inside container
31 raw: "sh -lc 'ls -l /tmp/hello_in_container.txt && wc -l /tmp/hello_in_container.txt'"
32
33 - name: Fetch the file back via podman cp
34 delegate_to: localhost
35 vars:
36 ansible_connection: local
37 command: >-
38 podman cp {{ inventory_hostname }}:/tmp/hello_in_container.txt /tmp/fetched_{{ inventory_hostname }}.txt
39
40