aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--roles/rc/defaults/main.yml9
-rw-r--r--roles/rc/defaults/os_alpine.yml1
-rw-r--r--roles/rc/defaults/os_openbsd.yml1
-rw-r--r--roles/rc/tasks/main.yml16
-rw-r--r--roles/rc/templates/os_alpine.j213
-rw-r--r--roles/rc/templates/os_openbsd.j217
-rw-r--r--roles/rc/vars/os_alpine.yml1
-rw-r--r--roles/rc/vars/os_openbsd.yml1
8 files changed, 59 insertions, 0 deletions
diff --git a/roles/rc/defaults/main.yml b/roles/rc/defaults/main.yml
new file mode 100644
index 0000000..f189142
--- /dev/null
+++ b/roles/rc/defaults/main.yml
@@ -0,0 +1,9 @@
+rc_dir: null
+
+rc_name: null
+rc_user: null
+rc_pexp: false
+rc_bg: true
+rc_args: ""
+rc_runtime_dir: /
+rc_description: managed by Ansible
diff --git a/roles/rc/defaults/os_alpine.yml b/roles/rc/defaults/os_alpine.yml
new file mode 100644
index 0000000..5b87a57
--- /dev/null
+++ b/roles/rc/defaults/os_alpine.yml
@@ -0,0 +1 @@
+rc_dir: /etc/init.d
diff --git a/roles/rc/defaults/os_openbsd.yml b/roles/rc/defaults/os_openbsd.yml
new file mode 100644
index 0000000..345a648
--- /dev/null
+++ b/roles/rc/defaults/os_openbsd.yml
@@ -0,0 +1 @@
+rc_dir: /etc/rc.d
diff --git a/roles/rc/tasks/main.yml b/roles/rc/tasks/main.yml
new file mode 100644
index 0000000..c691aae
--- /dev/null
+++ b/roles/rc/tasks/main.yml
@@ -0,0 +1,16 @@
+- name: check required variables
+ fail:
+ when: >
+ rc_name is none or
+ rc_user is none
+
+- name: include rc task per-system
+ include_vars: "os_{{ ansible_distribution | lower }}.yml"
+
+- name: generate rc script for desired service
+ template:
+ src: "os_{{ ansible_distribution | lower }}.j2"
+ dest: "{{ rc_dir }}/{{ rc_name }}"
+ owner: 0
+ group: 0
+ mode: 0755
diff --git a/roles/rc/templates/os_alpine.j2 b/roles/rc/templates/os_alpine.j2
new file mode 100644
index 0000000..a84d787
--- /dev/null
+++ b/roles/rc/templates/os_alpine.j2
@@ -0,0 +1,13 @@
+#!/sbin/openrc-run
+# managed by Ansible
+
+supervisor="supervise-daemon"
+
+description="{{ rc_name }} {{ rc_description }}"
+description_reload="Reload {{ rc_name }}"
+
+command="{{ rc_cmd }}"
+command_args="{{ rc_args }}"
+command_user="{{ rc_user }}"
+
+directory="{{ rc_runtime_dir }}"
diff --git a/roles/rc/templates/os_openbsd.j2 b/roles/rc/templates/os_openbsd.j2
new file mode 100644
index 0000000..cc1f444
--- /dev/null
+++ b/roles/rc/templates/os_openbsd.j2
@@ -0,0 +1,17 @@
+#!/bin/ksh
+# managed by Ansible
+
+daemon="{{ rc_cmd }}"
+daemon_flags="{{ rc_args }}"
+daemon_user="{{ rc_user }}"
+daemon_dir="{{ rc_runtime_dir }}"
+
+rc_bg="{{ "YES" if rc_bg else "NO" }}"
+
+{% if rc_pexp is defined and rc_pexp %}
+pexp="${daemon} ${daemon_flags}"
+{% endif %}
+
+. /etc/rc.d/rc.subr
+
+rc_cmd $1
diff --git a/roles/rc/vars/os_alpine.yml b/roles/rc/vars/os_alpine.yml
new file mode 100644
index 0000000..5b87a57
--- /dev/null
+++ b/roles/rc/vars/os_alpine.yml
@@ -0,0 +1 @@
+rc_dir: /etc/init.d
diff --git a/roles/rc/vars/os_openbsd.yml b/roles/rc/vars/os_openbsd.yml
new file mode 100644
index 0000000..345a648
--- /dev/null
+++ b/roles/rc/vars/os_openbsd.yml
@@ -0,0 +1 @@
+rc_dir: /etc/rc.d
remember that computers suck.