commit 667ada2402080c5ca8b6cab0efd8f719da06eb3d Author: Patrick Cao Huu Thien Date: Wed Oct 11 19:02:57 2023 +0200 init diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..783a965 --- /dev/null +++ b/README.rst @@ -0,0 +1,16 @@ +Terraform module to replace syslogd with rsyslog + +Usage +----- + +In the root terraform add:: + + module "rsyslog" { + source = "git::https://git.dalembert.upmc.fr/terraform/module_alpine_rsyslog" + connection_ip = var.eth0_ip + connection_private_key = file(var.pm_private_key) + } + + +.. vim: spelllang=en: + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..456a4be --- /dev/null +++ b/main.tf @@ -0,0 +1,36 @@ + +resource "null_resource" "rsyslog" { + connection { + type = "ssh" + user = "root" + host = var.connection_ip + private_key = var.connection_private_key + } + + provisioner "file" { + source = "${path.module}/rsyslog.conf" + destination = "/tmp/rsyslog.conf" + } + + # execute postinstall script + provisioner "remote-exec" { + inline = [ + "echo '# install rsyslog'", + "apk add --no-cache rsyslog", + # + "echo '# disable service syslog'", + "rc-service syslog stop", + "rc-update del syslog", + "rc-update del syslog boot", + # + "echo '# configuration service rsyslog'", + "rc-service rsyslog stop", + "mv /tmp/rsyslog.conf /etc/rsyslog.conf", + "rc-service rsyslog start", + "rc-update add rsyslog boot", + # + "echo;echo '# VM must be restarted to clean syslogd'", + ] + } + +} diff --git a/rsyslogd-checkconf b/rsyslogd-checkconf new file mode 100755 index 0000000..9ef2739 --- /dev/null +++ b/rsyslogd-checkconf @@ -0,0 +1 @@ +rsyslogd -f /etc/rsyslog.conf -N1 diff --git a/rsyslogd-reload b/rsyslogd-reload new file mode 100755 index 0000000..1cd00f2 --- /dev/null +++ b/rsyslogd-reload @@ -0,0 +1,7 @@ +if rsyslogd-checkconf +then + echo "Config OK" + rc-service rsyslog restart +else + echo "Abort restarting" +fi diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..b2ff069 --- /dev/null +++ b/variables.tf @@ -0,0 +1,11 @@ +variable "connection_ip" { + type = string + description = "ipv4" +} + +variable "connection_private_key" { + type = string + description = "private key for terraform connection" + sensitive = true +} +