feat: Use ansible module for podman

This commit is contained in:
pulsar89.5 2024-06-06 02:16:51 +02:00
parent b5484b1c73
commit 60737c9a5a
5 changed files with 54 additions and 39 deletions

View File

@ -3,6 +3,9 @@
podman_configure_rsyslog: true podman_configure_rsyslog: true
podman_ssh_host: "{{ inventory_hostname }}"
podman_ssh_port: 22
podman_containers: [] podman_containers: []
# Exemple: # Exemple:
# - image: docker.io/wallabag/wallabag:latest # - image: docker.io/wallabag/wallabag:latest

View File

@ -1,6 +1,20 @@
--- ---
# handlers file for exim4 # handlers file for exim4
- name: Redémarrer l'instance
ansible.builtin.reboot:
become: true
- name: Attendre que le port SSH soit ouvert
ansible.builtin.wait_for:
host: "{{ podman_ssh_host }}"
port: "{{ podman_ssh_port }}"
search_regex: OpenSSH
delay: 30
timeout: 900
sleep: 10
delegate_to: 127.0.0.1
- name: Redémarrer rsyslog.service - name: Redémarrer rsyslog.service
ansible.builtin.systemd: ansible.builtin.systemd:
state: restarted state: restarted

View File

@ -10,39 +10,23 @@
comment: Dedicated Podman user ({{ container.name }}) comment: Dedicated Podman user ({{ container.name }})
update_password: on_create update_password: on_create
password_lock: true password_lock: true
system: true
shell: /bin/bash shell: /bin/bash
- name: Créer le chemin de stockage des définitions - name: Create a Quadlet file
ansible.builtin.file: containers.podman.podman_container:
path: "{{ container_basepath }}" hostname: "{{ container.hostname | default(inventory_hostname) }}"
state: directory name: "{{ container.name }}"
owner: "{{ container_user }}" image: "{{ container.image }}"
group: "{{ container_user }}" state: quadlet
mode: u=rwX,g=rwX,o= device: "{{ container.device | default(omit) }}"
become: true ports: "{{ container.ports | default(omit) }}"
volumes: "{{ container.volumes | default(omit) }}"
- name: Déployer le conteneur userns: "{{ container.userns | default(omit) }}"
ansible.builtin.template: mount: "{{ container.mount | default(omit) }}"
src: podman-quadlet.container.j2 publish: "{{ container.publish | default(omit) }}"
dest: "{{ container_basepath }}/{{ container_filename }}" env: "{{ container.env | default(omit) }}"
owner: "{{ container_user }}" quadlet_options: "{{ container.quadlet_options | default(omit) }}"
group: "{{ container_user }}" recreate: true
mode: u=rw,g=rw,o=
become: true
register: deploy_container
- name: Activer le lingering
ansible.builtin.command:
cmd: "loginctl enable-linger {{ container_user }}"
creates: /var/lib/systemd/linger/{{ container_user }}
become: true
- name: Démarrer ou redémarrer le conteneur
ansible.builtin.systemd_service:
name: "{{ container_filename | replace('.container', '.service') }}"
state: "{{ 'restarted' if deploy_container.changed else 'started' }}"
enabled: true
daemon_reload: true
scope: user
become: true become: true
become_user: "{{ container_user }}" become_user: "{{ container_user }}"

View File

@ -1,17 +1,31 @@
--- ---
# tasks file for podman # tasks file for podman
- name: Installer les paquets - name: Installer les pré-requis
ansible.builtin.apt: ansible.builtin.apt:
name: name:
- dbus-user-session - dbus-user-session
- podman
- rootlesskit - rootlesskit
- slirp4netns - slirp4netns
- systemd-container - systemd-container
state: present state: present
become: true
notify:
- Redémarrer l'instance
- Attendre que le port SSH soit ouvert
- name: Installer podman
ansible.builtin.apt:
name: podman
state: present
default_release: sid default_release: sid
become: true become: true
notify:
- Redémarrer l'instance
- Attendre que le port SSH soit ouvert
- name: Exécuter les handlers
ansible.builtin.meta: flush_handlers
- name: Déployer la configuration de rsyslog - name: Déployer la configuration de rsyslog
ansible.builtin.template: ansible.builtin.template:

View File

@ -2,17 +2,17 @@
# tasks file for podman # tasks file for podman
- name: Importer les tâches d'installation - name: Importer les tâches d'installation
ansible.builtin.import_tasks:
file: installation.yml
tags: installation tags: installation
ansible.builtin.import_tasks: installation.yml
- name: Importer les tâches de configuration - name: Importer les tâches de configuration
tags: configuration ansible.builtin.include_tasks:
ansible.builtin.include_tasks: configuration.yml file: configuration.yml
loop: "{{ podman_containers }}" loop: "{{ podman_containers }}"
loop_control: loop_control:
label: "{{ container.name }}" label: "{{ container.name }}"
loop_var: container loop_var: container
vars: vars:
container_user: "podman-{{ container.user | default(container.name) }}" container_user: "podman-{{ container.user | default(container.name) }}"
container_basepath: "/home/{{ container_user }}/.config/containers/systemd" tags: configuration
container_filename: "podman-{{ container.name }}.container"