Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(famedly_sync): add role #239

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions roles/famedly_sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# `famedly.base.famedly_sync` ansible role for `famedly-sync`

## Description

Deploys [`famedly/famedly-sync`](https://github.com/famedly/famedly-sync) in a
docker container.

## Requirements

The role needs to be run as root.

## Usage

- `famedly_sync_config`: dictionary that contains `famedly-sync` configuration
30 changes: 30 additions & 0 deletions roles/famedly_sync/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
famedly_sync_path: /opt/famedly-sync

famedly_sync_container_image_force_pull: "{{ famedly_sync_container_image_tag is defined }}"

famedly_sync_version: "0.6.0"

famedly_sync_container_image_reference: >-
{{
famedly_sync_container_image_repository
+ ':'
+ famedly_sync_container_image_tag | default('v' + famedly_sync_version)
}}
famedly_sync_container_image_repository: >-
{{
(
container_registries[famedly_sync_container_image_registry]
| default(famedly_sync_container_image_registry)
)
+ '/'
+ famedly_sync_container_image_namespace | default('')
+ famedly_sync_container_image_name
}}
famedly_sync_container_image_registry: "docker-oss.nexus.famedly.de"
famedly_sync_container_image_name: "famedly-sync-agent"

famedly_sync_docker_networks:
- name: host

famedly_sync_docker_volumes:
- "{{ famedly_sync_path }}:/opt/famedly-sync:rw"
8 changes: 8 additions & 0 deletions roles/famedly_sync/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Restart famedly-sync.timer
listen: "restart famedly-sync.timer"
become: true
ansible.builtin.systemd:
daemon_reload: true
name: famedly-sync.timer
state: restarted
55 changes: 55 additions & 0 deletions roles/famedly_sync/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---

- name: "Assert config is defined"
ansible.builtin.assert:
that: "famedly_sync_config is defined"
fail_msg: "famedly_sync_config needs to be defined per host"

- name: "Create volume path"
ansible.builtin.file:
path: "{{ item }}"
state: "directory"
mode: "0700"
lrsksr marked this conversation as resolved.
Show resolved Hide resolved
loop:
- "{{ famedly_sync_path }}"

- name: "Ensure container image is present locally"
community.docker.docker_image:
name: "{{ famedly_sync_container_image_reference }}"
source: "pull"
state: "present"
force_source: "{{ famedly_sync_container_image_force_pull }}"

- name: "Ensure container is present"
community.docker.docker_container:
name: famedly-sync
image: "{{ famedly_sync_container_image_reference }}"
state: "present"
volumes: "{{ famedly_sync_docker_volumes }}"
labels: "{{ famedly_sync_docker_labels | default(omit, True) }}"
networks: "{{ famedly_sync_docker_networks }}"

- name: "Deploy config"
ansible.builtin.copy:
# famedly_sync_config is defined, because the assertion passed
content: "{{ famedly_sync_config | to_nice_yaml(indent=2) }}" # noqa: jinja[invalid]
dest: "{{ famedly_sync_path }}/config.yaml"
mode: "0400"

- name: "Install systemd units"
ansible.builtin.template:
lrsksr marked this conversation as resolved.
Show resolved Hide resolved
src: "{{ item }}.j2"
dest: "/etc/systemd/system/{{ item }}"
owner: root
group: root
mode: "0644"
notify: "restart famedly-sync.timer"
loop:
- famedly-sync.service
- famedly-sync.timer

- name: "Enable famedly-sync.timer"
ansible.builtin.systemd:
name: famedly-sync.timer
state: started
enabled: true
6 changes: 6 additions & 0 deletions roles/famedly_sync/templates/famedly-sync.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Unit]
Description=Sync users from LDAP to Zitadel

[Service]
Type=oneshot
ExecStart=/usr/bin/docker start -a famedly-sync
9 changes: 9 additions & 0 deletions roles/famedly_sync/templates/famedly-sync.timer.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Sync users from LDAP to Zitadel regularly

[Timer]
OnBootSec=15min
OnUnitActiveSec=15min

[Install]
WantedBy=timers.target
Loading