Skip to content

Commit cafd799

Browse files
committed
ansible - fix playbook and podman issues
1 parent 0d4c8d7 commit cafd799

File tree

2 files changed

+71
-25
lines changed

2 files changed

+71
-25
lines changed

ansible/clean_podman_mess.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Stop all running containers
4+
echo "Stopping all running containers..."
5+
podman stop -a
6+
7+
# Remove all containers (forcefully)
8+
echo "Removing all containers..."
9+
podman rm -af
10+
11+
# Remove all images (forcefully)
12+
echo "Removing all images..."
13+
podman rmi -af
14+
15+
# Clean up any additional unused data
16+
echo "Cleaning up system..."
17+
podman system prune -a -f --volumes
18+
19+
20+
# PODMAN CNI NETWORKING BUG/MISCONFIG
21+
22+
# The CNI configuration is set to version 1.0.0, which is not compatible.
23+
# It should be version 0.4.0. This requires manual adjustment each time.
24+
# bug report here: https://bugs.launchpad.net/ubuntu/+source/libpod/+bug/2024394
25+
26+
# Remove the specific network and recreate it
27+
# echo "Removing and recreating the 'podman' network..."
28+
# podman network rm podman 2>/dev/null
29+
# podman network create podman
30+
31+
32+
# Remove any remaining container storage
33+
echo "Cleaning up remaining container storage..."
34+
CONTAINER_ID=$(podman ps -a --filter "name=java_test_container" --format "{{.ID}}")
35+
if [ -n "$CONTAINER_ID" ]; then
36+
sudo rm -rf /var/lib/containers/storage/overlay/*${CONTAINER_ID}*
37+
sudo rm -rf /var/lib/containers/storage/overlay-containers/*${CONTAINER_ID}*
38+
sudo rm -rf /var/lib/containers/storage/volumes/*${CONTAINER_ID}*
39+
fi
40+
41+
# Restart Podman
42+
echo "Restarting Podman..."
43+
sudo systemctl restart podman
44+
45+
echo "Cleanup completed successfully."
46+

ansible/latest_java_testbed.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
---
2-
- hosts: localhost
3-
become: yes
2+
- name: Build and run a Java container with Podman
3+
hosts: localhost
44
tasks:
5-
- name: Install Podman if not present
6-
apt:
7-
name: podman
8-
state: present
9-
update_cache: yes
5+
- name: Generate a random number
6+
set_fact:
7+
random_number: "{{ 9999 | random }}"
108

11-
- name: Pull the latest OpenJDK image using Podman
12-
ansible.builtin.command:
13-
cmd: podman pull docker.io/library/openjdk:latest
14-
register: podman_pull_result
9+
- name: Remove existing container if it exists
10+
command: >
11+
podman rm -f java_test_container_{{ random_number }}
12+
ignore_errors: yes
13+
failed_when: false
1514

16-
- name: Ensure the image is pulled
17-
debug:
18-
msg: "Pulled image: {{ podman_pull_result.stdout }}"
15+
- name: Check if Podman network exists
16+
command: >
17+
podman network inspect podman
18+
register: network_inspect
19+
ignore_errors: yes
1920

20-
- name: Run Java container with Podman and mount the test-code directory
21-
ansible.builtin.command:
22-
cmd: podman run -d --name java_test_container -v /home/user/test-code:/usr/src/myapp docker.io/library/openjdk:latest sleep infinity
23-
register: podman_run_result
21+
- name: Create Podman network if it does not exist
22+
command: >
23+
podman network create podman
24+
when: network_inspect.rc != 0
2425

25-
- name: Ensure the container is running
26-
debug:
27-
msg: "Container running: {{ podman_run_result.stdout }}"
28-
29-
- name: Display running Podman containers
30-
ansible.builtin.command:
31-
cmd: podman ps
26+
- name: Run Java container interactively with Podman and mount the test-code directory
27+
command: >
28+
podman run -it --name java_test_container_{{ random_number }}
29+
-v /home/edo9k/Documentos/repos/learn:/usr/src/myapp
30+
docker.io/library/openjdk:latest
31+
/bin/bash
3232

0 commit comments

Comments
 (0)