diff --git a/roles/synapse/README.md b/roles/synapse/README.md index ced5eb0..054bc56 100644 --- a/roles/synapse/README.md +++ b/roles/synapse/README.md @@ -18,12 +18,12 @@ The following variables need to be populated: ## Deployment methods -### Docker +- `docker` +- `podman` -Set `synapse_deployment_method: docker` to deploy synapse in docker container(s). -This is currently the default. +Set `synapse_deployment_method` to one of the supported deployment methods. +The current default is `docker`. -### Planned methods +### Planned deployment methods -- virtual env + systemd -- podman +- `venv` - Python virtual env supervised with `systemd` diff --git a/roles/synapse/defaults/main/container.yml b/roles/synapse/defaults/main/container.yml index c5b4e6d..f17c2e0 100644 --- a/roles/synapse/defaults/main/container.yml +++ b/roles/synapse/defaults/main/container.yml @@ -18,10 +18,14 @@ synapse_container_image_repository: >-2 synapse_container_image_source: pull synapse_container_image_tag: ~ synapse_container_env: {} -synapse_container_user: >- +synapse_container_user: >-2 {{ ((synapse_user_info is defined) and ('uid' in synapse_user_info)) | ternary(synapse_user_info.uid, synapse_user) }} -synapse_container_group: ~ +synapse_container_group: >-2 + {{ ((synapse_user_info is defined) and ('group' in synapse_user_info)) + | ternary(synapse_user_info.group, synapse_user) }} +synapse_container_groups: + - "{{ synapse_container_group }}" synapse_container_ports: ~ synapse_container_labels: ~ synapse_container_ulimits: ~ @@ -32,8 +36,14 @@ synapse_container_etc_hosts: ~ synapse_container_memory: ~ synapse_container_memory_reservation: ~ synapse_container_memory_swap: ~ -synapse_container_state: "started" -synapse_container_restart_policy: "unless-stopped" +synapse_container_state: >-2 + {{ (synapse_state == 'present') + | ternary('started', 'absent') }} +synapse_container_restart_policy: >-2 + {{ (synapse_deployment_method == 'docker') + | ternary('unless-stopped', ((synapse_deployment_method == 'podman') + | ternary('on-failure', 'always'))) + }} synapse_container_volumes: ~ synapse_container_default_volumes: diff --git a/roles/synapse/tasks/deploy-podman.yml b/roles/synapse/tasks/deploy-podman.yml new file mode 100644 index 0000000..6619a61 --- /dev/null +++ b/roles/synapse/tasks/deploy-podman.yml @@ -0,0 +1,31 @@ +--- +- name: Ensure container image '{{ synapse_container_image }}' is {{ synapse_state }} on host + containers.podman.podman_image: + name: "{{ synapse_container_image }}" + state: "{{ synapse_state }}" + pull: "{{ synapse_container_image_source == 'pull' }}" + force: "{{ synapse_container_image_tag | default(false, true) | bool }}" + register: synapse_container_image_info + until: synapse_container_image_info is success + retries: 5 + delay: 3 + +- name: Ensure synapse container '{{ synapse_container_name }}' is {{ synapse_container_state }} + containers.podman.podmain_container: + name: "{{ synapse_container_name }}" + image: "{{ synapse_container_image }}" + env: "{{ synapse_container_env | default(omit, true) }}" + user: "{{ synapse_container_user | default(omit, true) }}" + groups: "{{ synapse_container_groups | default(omit, true) }}" + ports: "{{ synapse_container_ports | default(omit, true) }}" + labels: "{{ synapse_container_labels | default(omit, true) }}" + ulimits: "{{ synapse_container_ulimits | default(omit, true) }}" + volumes: "{{ synapse_container_all_volumes }}" + network: "{{ synapse_container_networks | default(omit, true) }}" + dns_servers: "{{ synapse_container_dns_servers | default(omit, true) }}" + etc_hosts: "{{ synapse_container_etc_hosts | default(omit, true) }}" + memory: "{{ synapse_container_memory | default(omit, true) }}" + memory_reservation: "{{ synapse_container_memory_reservation | default(omit, true) }}" + memory_swap: "{{ synapse_container_memory_swap | default(omit, true) }}" + restart_policy: "{{ synapse_container_restart_policy }}" + state: "{{ synapse_container_state }}" diff --git a/roles/synapse/vars/main.yml b/roles/synapse/vars/main.yml index 00fe1c8..ff16b4a 100644 --- a/roles/synapse/vars/main.yml +++ b/roles/synapse/vars/main.yml @@ -5,6 +5,7 @@ synapse_states: synapse_deployment_methods: - docker + - podman synapse_required_variables: - synapse_domain