config/roles/dev_host/tasks/main.yml
2025-08-08 22:26:14 +03:00

37 lines
1.3 KiB
YAML

# os based on https://github.com/sandorex/config/blob/master/playbooks/container-dev.yml
- name: Check if container already exists
containers.podman.podman_container_info:
name: '{{ container_name }}'
register: container_info
- name: Create container using distrobox
ansible.builtin.command:
# requires distrobox version 1.7
# add python3 to allow ansible to work
# add ansible to run local roles without host (?)
cmd: >-
distrobox create --yes --no-entry --pull
--image '{{ container_image }}:{{ container_image_tag }}'
--name '{{ container_name }}'
--hostname '{{ ansible_hostname }}'
--additional-packages 'python3 ansible'
when: container_info.containers | length == 0
- name: Start the container
ansible.builtin.command:
cmd: 'distrobox enter --name {{ container_name }} -- sh -c ''exit'''
# start if not running or if not defined
when: not (container_info.containers[0].State.Running | default(false))
- name: Add container to host
changed_when: no
ansible.builtin.add_host:
name: '{{ container_name }}' # ??
groups: containers
ansible_connection: distrobox
ansible_host: '{{ container_name }}'
ansible_user: '{{ ansible_user_id }}'
fedora_version: '{{ container_image_tag }}' # ??
# container setup is done outside (?)