| 1 |
--- |
| 2 |
- name: Test podman container copy host-container |
| 3 |
block: |
| 4 |
- name: Generate random value for container name |
| 5 |
ansible.builtin.set_fact: |
| 6 |
container_name: "{{ 'ansible-test-podman-%0x' % ((2**32) | random) }}" |
| 7 |
file_name: sample_file |
| 8 |
|
| 9 |
- name: Start container |
| 10 |
containers.podman.podman_container: |
| 11 |
executable: "{{ test_executable | default('podman') }}" |
| 12 |
name: "{{ container_name }}" |
| 13 |
image: alpine:3.7 |
| 14 |
state: started |
| 15 |
command: sleep 1d |
| 16 |
|
| 17 |
- name: Create local file to copy |
| 18 |
ansible.builtin.copy: |
| 19 |
content: | |
| 20 |
This file tests if host -> container copy is working |
| 21 |
dest: "{{ playbook_dir }}/{{ file_name }}" |
| 22 |
mode: "0755" |
| 23 |
|
| 24 |
- name: Copy local file to containers root folder |
| 25 |
containers.podman.podman_container_copy: |
| 26 |
executable: "{{ test_executable | default('podman') }}" |
| 27 |
src: "{{ playbook_dir }}/{{ file_name }}" |
| 28 |
dest: "/{{ file_name }}" |
| 29 |
container: "{{ container_name }}" |
| 30 |
|
| 31 |
- name: Verify that the file exists in the container |
| 32 |
containers.podman.podman_container_exec: |
| 33 |
executable: "{{ test_executable | default('podman') }}" |
| 34 |
name: "{{ container_name }}" |
| 35 |
command: "cat /{{ file_name }}" |
| 36 |
|
| 37 |
always: |
| 38 |
- name: Remove container |
| 39 |
containers.podman.podman_container: |
| 40 |
executable: "{{ test_executable | default('podman') }}" |
| 41 |
name: "{{ container_name }}" |
| 42 |
state: absent |
| 43 |
|
| 44 |
- name: Remove local file |
| 45 |
ansible.builtin.file: |
| 46 |
path: "{{ playbook_dir }}/{{ file_name }}" |
| 47 |
state: absent |
| 48 |
|
| 49 |
- name: Test podman container copy container-host |
| 50 |
block: |
| 51 |
- name: Generate random value for container name |
| 52 |
ansible.builtin.set_fact: |
| 53 |
container_name: "{{ 'ansible-test-podman-%0x' % ((2**32) | random) }}" |
| 54 |
file_name: sample_file |
| 55 |
|
| 56 |
- name: Start container |
| 57 |
containers.podman.podman_container: |
| 58 |
executable: "{{ test_executable | default('podman') }}" |
| 59 |
name: "{{ container_name }}" |
| 60 |
image: alpine:3.7 |
| 61 |
state: started |
| 62 |
command: sleep 1d |
| 63 |
|
| 64 |
- name: Create file in the container for further copy |
| 65 |
containers.podman.podman_container_exec: |
| 66 |
executable: "{{ test_executable | default('podman') }}" |
| 67 |
name: "{{ container_name }}" |
| 68 |
command: sh -c 'echo "This file tests if container -> host copy is working" > /{{ file_name }}' |
| 69 |
|
| 70 |
- name: Verify that the file exists in the container |
| 71 |
containers.podman.podman_container_exec: |
| 72 |
executable: "{{ test_executable | default('podman') }}" |
| 73 |
name: "{{ container_name }}" |
| 74 |
command: "cat /{{ file_name }}" |
| 75 |
|
| 76 |
- name: Copy local file to containers root folder |
| 77 |
containers.podman.podman_container_copy: |
| 78 |
executable: "{{ test_executable | default('podman') }}" |
| 79 |
src: "/{{ file_name }}" |
| 80 |
dest: "{{ playbook_dir }}/{{ file_name }}" |
| 81 |
container: "{{ container_name }}" |
| 82 |
from_container: true |
| 83 |
|
| 84 |
- name: Check file |
| 85 |
ansible.builtin.stat: |
| 86 |
path: "{{ playbook_dir }}/{{ file_name }}" |
| 87 |
register: copied_file |
| 88 |
|
| 89 |
- name: Check it's present |
| 90 |
ansible.builtin.assert: |
| 91 |
that: |
| 92 |
- copied_file.stat.exists |
| 93 |
|
| 94 |
always: |
| 95 |
- name: Remove container |
| 96 |
containers.podman.podman_container: |
| 97 |
executable: "{{ test_executable | default('podman') }}" |
| 98 |
name: "{{ container_name }}" |
| 99 |
state: absent |
| 100 |
|
| 101 |
- name: Remove local file |
| 102 |
ansible.builtin.file: |
| 103 |
path: "{{ playbook_dir }}/{{ file_name }}" |
| 104 |
state: absent |