This repository has been archived on 2023-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
salt-states_old/podman/containers.sls

61 lines
1.7 KiB
Plaintext
Raw Normal View History

2022-11-02 10:18:20 +00:00
{% set user = salt['pillar.get']('podman:user', 'root') %}
{% set home = salt['user.info'](user).home %}
{% set group = salt['pillar.get']('podman:group', 'root') %}
{% for name, args in salt['pillar.get']('containers', {} ).items() %}
Create container manage file for {{ name }}:
file.managed:
- name: "{{ home }}/bin/{{ name }}.sh"
- source: salt://podman/files/container.sh.jinja
- template: jinja
- user: {{ user }}
- group: {{ group }}
- mode: "0750"
- context:
container: {{ name }}
args: {{ args }}
{% if args['volumes'] is defined %}
{% for volume, mount in args['volumes'].items() %}
Create {{ volume }} volume for {{ name }}:
cmd.run:
- name: podman volume create {{ name }}-{{ volume }}
- runas: {{ user }}
- unless: podman volume exists {{ name }}-{{ volume }}
{% endfor %}
{% endif %}
Create container {{ name }}:
cmd.run:
- name: "{{ home }}/bin/{{ name }}.sh --create"
- runas: {{ user }}
- unless: podman container exists {{ name }}
Create container {{ name }} unit file:
cmd.run:
- name: podman generate systemd --name {{ name }} > {{ home }}/.config/systemd/user/{{ name }}.service
- runas: {{ user }}
- onchanges:
- cmd: Create container {{ name }}
Run user daemon reload for {{ name }} unit:
cmd.run:
- name: systemctl --user daemon-reload
- runas: {{ user }}
- onchanges:
- cmd: Create container {{ name }} unit file
start container {{ name }}:
cmd.run:
- name: "{{ home }}/bin/{{ name }}.sh --start"
- runas: {{ user }}
- unless: "{{ home }}/bin/{{ name }}.sh --is-running"
- onchanges:
- cmd: Run user daemon reload for {{ name }} unit
{% endfor %}