| 1 |
- name: Validate scp transport behavior in podman_image |
| 2 |
block: |
| 3 |
- name: Fail when scp transport is used without destination |
| 4 |
containers.podman.podman_image: |
| 5 |
executable: "{{ test_executable | default('podman') }}" |
| 6 |
name: testimage |
| 7 |
pull: false |
| 8 |
push: true |
| 9 |
push_args: |
| 10 |
transport: scp |
| 11 |
register: scp_missing_dest |
| 12 |
ignore_errors: true |
| 13 |
|
| 14 |
- name: Ensure scp without dest fails with clear message |
| 15 |
assert: |
| 16 |
that: |
| 17 |
- scp_missing_dest is failed |
| 18 |
- "'push_args.dest must be provided' in scp_missing_dest.msg" |
| 19 |
|
| 20 |
|
| 21 |
- name: Build a local image to test scp transport idempotence |
| 22 |
containers.podman.podman_image: |
| 23 |
executable: "{{ test_executable | default('podman') }}" |
| 24 |
name: testimage_scp |
| 25 |
path: /var/tmp/build |
| 26 |
register: built_local |
| 27 |
|
| 28 |
- name: Try to scp push to a fake remote (should fail on CI env without remote) |
| 29 |
containers.podman.podman_image: |
| 30 |
executable: "{{ test_executable | default('podman') }}" |
| 31 |
name: testimage_scp |
| 32 |
pull: false |
| 33 |
push: true |
| 34 |
push_args: |
| 35 |
dest: user@server |
| 36 |
transport: scp |
| 37 |
register: scp_push_fake |
| 38 |
ignore_errors: true |
| 39 |
|
| 40 |
- name: Ensure scp push to fake remote fails but reports action |
| 41 |
assert: |
| 42 |
that: |
| 43 |
- built_local is changed |
| 44 |
- scp_push_fake is failed |
| 45 |
- scp_push_fake.actions is defined |
| 46 |
|
| 47 |
- name: Prepare SSH access to localhost for scp tests |
| 48 |
block: |
| 49 |
|
| 50 |
- name: Ensure SSH keys exist |
| 51 |
ansible.builtin.shell: >- |
| 52 |
ssh-keygen -b 2048 -t rsa -f {{ lookup('env','HOME') }}/.ssh/id_rsa -N "" || true |
| 53 |
args: |
| 54 |
creates: "{{ lookup('env','HOME') }}/.ssh/id_rsa" |
| 55 |
|
| 56 |
- name: Get public key for user |
| 57 |
ansible.builtin.command: >- |
| 58 |
cat {{ lookup('env','HOME') }}/.ssh/id_rsa.pub |
| 59 |
register: public_key |
| 60 |
|
| 61 |
- name: Authorize our public key for localhost for user |
| 62 |
ansible.posix.authorized_key: |
| 63 |
user: "{{ lookup('env','USER') }}" |
| 64 |
state: present |
| 65 |
key: "{{ public_key.stdout }}" |
| 66 |
|
| 67 |
- name: Authorize our public key for localhost for root user |
| 68 |
become: true |
| 69 |
ansible.posix.authorized_key: |
| 70 |
user: root |
| 71 |
state: present |
| 72 |
key: "{{ public_key.stdout }}" |
| 73 |
|
| 74 |
- name: Start SSH service (Ubuntu uses 'ssh') |
| 75 |
ansible.builtin.systemd_service: |
| 76 |
name: ssh |
| 77 |
state: started |
| 78 |
become: true |
| 79 |
ignore_errors: true |
| 80 |
|
| 81 |
- name: Start SSH service (fallback to 'sshd') |
| 82 |
ansible.builtin.systemd_service: |
| 83 |
name: sshd |
| 84 |
state: started |
| 85 |
become: true |
| 86 |
ignore_errors: true |
| 87 |
|
| 88 |
- name: Verify we can SSH to localhost non-interactively |
| 89 |
ansible.builtin.command: >- |
| 90 |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{ lookup('env','USER') }}@localhost true |
| 91 |
|
| 92 |
- name: Build a local image for scp to localhost |
| 93 |
containers.podman.podman_image: |
| 94 |
executable: "{{ test_executable | default('podman') }}" |
| 95 |
name: testimage_scp_local |
| 96 |
path: /var/tmp/build |
| 97 |
register: built_localhost |
| 98 |
|
| 99 |
- name: Add system connection for Podman < 5 |
| 100 |
ansible.builtin.command: podman system connection add local --identity {{ lookup('env','HOME') }}/.ssh/id_rsa {{ lookup('env','USER') }}@127.0.0.1 |
| 101 |
|
| 102 |
- name: Add system connection for root user for Podman < 5 |
| 103 |
ansible.builtin.command: podman system connection add rootlocal --identity {{ lookup('env','HOME') }}/.ssh/id_rsa [email protected] |
| 104 |
|
| 105 |
- name: Push image to localhost via scp transport |
| 106 |
containers.podman.podman_image: |
| 107 |
executable: "{{ test_executable | default('podman') }}" |
| 108 |
name: testimage_scp_local |
| 109 |
pull: false |
| 110 |
push: true |
| 111 |
push_args: |
| 112 |
dest: "local::newimage" |
| 113 |
transport: scp |
| 114 |
register: scp_localhost_push |
| 115 |
|
| 116 |
- name: Validate scp localhost push executed |
| 117 |
assert: |
| 118 |
that: |
| 119 |
- built_localhost is changed |
| 120 |
- scp_localhost_push is changed |
| 121 |
- scp_localhost_push.actions is defined |
| 122 |
- scp_localhost_push.podman_actions is defined |
| 123 |
- scp_localhost_push.actions | select('search', 'image scp') | list | length > 0 |
| 124 |
|
| 125 |
- name: Push image to localhost via scp transport root user |
| 126 |
containers.podman.podman_image: |
| 127 |
executable: "{{ test_executable | default('podman') }}" |
| 128 |
name: testimage_scp_local |
| 129 |
pull: false |
| 130 |
push: true |
| 131 |
push_args: |
| 132 |
dest: "rootlocal" |
| 133 |
transport: scp |
| 134 |
register: scp_localhost_push |
| 135 |
|
| 136 |
- name: Validate scp localhost push executed |
| 137 |
assert: |
| 138 |
that: |
| 139 |
- built_localhost is changed |
| 140 |
- scp_localhost_push is changed |
| 141 |
- scp_localhost_push.actions is defined |
| 142 |
- scp_localhost_push.podman_actions is defined |
| 143 |
- scp_localhost_push.actions | select('search', 'image scp') | list | length > 0 |
| 144 |
|
| 145 |
- name: Ensure image is available for root user |
| 146 |
become: true |
| 147 |
ansible.builtin.command: >- |
| 148 |
podman images --format '{{ '{{.Repository}}:{{.Tag}}' }}' testimage_scp_local |
| 149 |
register: scp_localhost_root_check |
| 150 |
|
| 151 |
- name: Validate image is available for root user |
| 152 |
assert: |
| 153 |
that: |
| 154 |
- "'testimage_scp_local:latest' in scp_localhost_root_check.stdout" |
| 155 |
- scp_localhost_root_check.stderr == '' |