From f48693ca5eb971fba061d33fdebbd9d414ad1752 Mon Sep 17 00:00:00 2001
From: "pulsar89.5" <pulsar89.5@ykn.fr>
Date: Tue, 1 Apr 2025 12:36:19 +0200
Subject: [PATCH] feat: Add compatibility with CoreOS

---
 handlers/main.yml       |  9 ++++++++-
 tasks/configuration.yml | 37 ++++++++++++++++++++++++++++++++++
 tasks/installation.yml  | 25 +++++++++++++++++++++++
 tasks/main.yml          | 44 ++++++-----------------------------------
 4 files changed, 76 insertions(+), 39 deletions(-)
 create mode 100644 tasks/configuration.yml
 create mode 100644 tasks/installation.yml

diff --git a/handlers/main.yml b/handlers/main.yml
index 436c7f1..3f262cb 100644
--- a/handlers/main.yml
+++ b/handlers/main.yml
@@ -1,7 +1,14 @@
 ---
 # handlers file for keepalived
 
-- name: Redémarrer keepalived.service
+- name: Apply installation
+  ansible.builtin.command:
+    argv:
+      - /usr/bin/rpm-ostree
+      - apply-live
+  become: true
+
+- name: Restart keepalived.service
   become: true
   ansible.builtin.systemd:
     state: restarted
diff --git a/tasks/configuration.yml b/tasks/configuration.yml
new file mode 100644
index 0000000..3c87119
--- /dev/null
+++ b/tasks/configuration.yml
@@ -0,0 +1,37 @@
+---
+# tasks file for keepalived
+
+- name: Deploy configuration
+  ansible.builtin.template:
+    src: keepalived.j2
+    dest: /etc/keepalived/keepalived.conf
+    owner: root
+    group: root
+    mode: u=rw,g=r,o=r
+  become: true
+  notify: Restart keepalived.service
+
+- name: Deploy sudoers configuration
+  ansible.builtin.template:
+    src: sudoers.j2
+    dest: /etc/sudoers.d/keepalived_script
+    owner: root
+    group: keepalived_script
+    mode: u=rwx,g=rx,o=
+    validate: /usr/sbin/visudo -cf %s
+  when:
+    - keepalived_notify_enable
+    - keepalived_sudoers_cmd | length > 0
+  become: true
+  notify: Restart keepalived.service
+
+- name: Deploy notify script
+  ansible.builtin.template:
+    src: notify.bash.j2
+    dest: /etc/keepalived/notify.bash
+    owner: root
+    group: keepalived_script
+    mode: u=rwx,g=rx,o=
+  when: keepalived_notify_enable
+  become: true
+  notify: Restart keepalived.service
diff --git a/tasks/installation.yml b/tasks/installation.yml
new file mode 100644
index 0000000..d5570f3
--- /dev/null
+++ b/tasks/installation.yml
@@ -0,0 +1,25 @@
+---
+# tasks file for keepalived
+
+- name: Install keepalived
+  ansible.builtin.apt:
+    name: keepalived
+  when: ansible_facts['pkg_mgr'] == "apt"
+  become: true
+
+- name: Install keepalived
+  ansible.builtin.command:
+    argv:
+      - /usr/bin/rpm-ostree
+      - install
+      - --allow-inactive
+      - --assumeyes
+      - --idempotent
+      - keepalived
+    creates: /usr/sbin/dnsmasq
+  when: ansible_facts['pkg_mgr'] == "atomic_container"
+  become: true
+  notify: Apply installation
+
+- name: Flush handlers
+  meta: flush_handlers
diff --git a/tasks/main.yml b/tasks/main.yml
index 35ee70a..cd1f556 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,42 +1,10 @@
 ---
 # tasks file for keepalived
 
-- name: Installer le paquet
-  ansible.builtin.apt:
-    name: keepalived
-  become: true
+- name: Include installation tasks
+  ansible.builtin.include_tasks:
+    file: installation.yml
 
-- name: Déployer la configuration
-  ansible.builtin.template:
-    src: keepalived.j2
-    dest: /etc/keepalived/keepalived.conf
-    owner: root
-    group: root
-    mode: u=rw,g=r,o=r
-  become: true
-  notify: Redémarrer keepalived.service
-
-- name: Déployer le fichier de configuration de sudoers
-  ansible.builtin.template:
-    src: sudoers.j2
-    dest: /etc/sudoers.d/keepalived_script
-    owner: root
-    group: keepalived_script
-    mode: u=rwx,g=rx,o=
-    validate: /usr/sbin/visudo -cf %s
-  when:
-    - keepalived_notify_enable
-    - keepalived_sudoers_cmd | length > 0
-  become: true
-  notify: Redémarrer keepalived.service
-
-- name: Déployer les scripts
-  ansible.builtin.template:
-    src: notify.bash.j2
-    dest: /etc/keepalived/notify.bash
-    owner: root
-    group: keepalived_script
-    mode: u=rwx,g=rx,o=
-  when: keepalived_notify_enable
-  become: true
-  notify: Redémarrer keepalived.service
+- name: Import configuration tasks
+  ansible.builtin.import_tasks:
+    file: configuration.yml