Ansible Podman


Ansible Podman

Podman is Red Hats alternative to docker and is a container technology,here we are going to use ansible with podman In a folder say ansible-projects create a inventory file named inventory

[nginx]

rockylinux  # hostname 

create a playbook podmanplaybook1.yml and call the role which you are going to create
 
---
- name: Install nginx
  hosts: nginx
  become: yes
 
  roles:
     - podman-nginx-role
Create a new role as below

ansible-galaxy init podman-nginx-role

In the file podman-nginx-role/tasks/main.yml enter the below, also create a folder mkdir -p /data/nginx/var/www/html

 

---
# tasks file for podman-nginx-role
- name: Pull an image
  containers.podman.podman_image:
    name: nginx:alpine

- name: Run container
  containers.podman.podman_container:
    name: container
    image: nginx:alpine
    state: started
    ports: 80:80
    volume:
       - /data/nginx/var/www/html:/usr/share/nginx/html

- name: Copy files
  copy:
    src: index.html
    dest: /data/nginx/var/www/html
  notify: restart nginx

in the file index.html under podman-nginx-role/files/index.html
 

This is a test page

Run the playbook as below, in this example i am using without ssh keys and would have installed sshpass using dnf install sshpass prior

ansible-playbook -i inventory podmanplaybook1.yml -k -v

podman images --all
podman -dt -p 80:80 --name test (imageid of downloaded image)
podman container list
Test using curl http://localhost