summaryrefslogtreecommitdiffstats
path: root/roles/ands_scripts
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2019-10-25 00:19:07 +0200
committerSuren A. Chilingaryan <csa@suren.me>2019-10-25 00:19:07 +0200
commit9e38736b93a6b737ecb53d1f41dadf45cbb22c1c (patch)
tree33cda4d193d83772e7fd0f45e7101452497be7d3 /roles/ands_scripts
parent15890ccdef55168e9753ff6957ce64096837c627 (diff)
downloaditm-9e38736b93a6b737ecb53d1f41dadf45cbb22c1c.tar.gz
itm-9e38736b93a6b737ecb53d1f41dadf45cbb22c1c.tar.bz2
itm-9e38736b93a6b737ecb53d1f41dadf45cbb22c1c.tar.xz
itm-9e38736b93a6b737ecb53d1f41dadf45cbb22c1c.zip
Various stuff to pre-configure compute nodes
Diffstat (limited to 'roles/ands_scripts')
-rw-r--r--roles/ands_scripts/defaults/main.yml1
-rw-r--r--roles/ands_scripts/tasks/main.yml29
-rw-r--r--roles/ands_scripts/templates/all/cron/maintain.j24
-rw-r--r--roles/ands_scripts/templates/all/scripts/subids.sh19
4 files changed, 53 insertions, 0 deletions
diff --git a/roles/ands_scripts/defaults/main.yml b/roles/ands_scripts/defaults/main.yml
new file mode 100644
index 0000000..ee3cb7b
--- /dev/null
+++ b/roles/ands_scripts/defaults/main.yml
@@ -0,0 +1 @@
+ands_script_path: "/opt/scripts"
diff --git a/roles/ands_scripts/tasks/main.yml b/roles/ands_scripts/tasks/main.yml
new file mode 100644
index 0000000..048b0da
--- /dev/null
+++ b/roles/ands_scripts/tasks/main.yml
@@ -0,0 +1,29 @@
+#- name: Install monitoring applications
+# package: name={{item}} state=present
+# with_items:
+# - sysstat
+
+- name: Create scripts directory
+ file: path="{{ ands_script_path }}" state=directory
+
+- name: "Deploy scripts"
+ copy: src="{{ item | quote }}" dest="{{ ands_script_path }}/{{ item | basename | quote }}" owner=root group=root mode=0755
+ with_fileglob:
+ - "{{ role_path }}/templates/all/scripts/*.sh"
+ - "{{ role_path }}/templates/{{ inventory_hostname }}/scripts/*.sh"
+
+- name: "Deploy script templates"
+ template: src="{{ item | quote }}" dest="{{ ands_script_path }}/{{ script_name }}" owner=root group=root mode=0755
+ vars:
+ script_name: "{{ item | basename | regex_replace('\\.j2','') }}"
+ with_fileglob:
+ - "{{ role_path }}/templates/all/scripts/*.j2"
+ - "{{ role_path }}/templates/{{ inventory_hostname }}/scripts/*.j2"
+
+- name: "Deploy cron jobs"
+ template: src="{{ item | quote }}" dest="/etc/cron.d/{{ cron_name }}" owner=root group=root mode=0644
+ vars:
+ cron_name: "{{ item | basename | regex_replace('\\.j2','') }}"
+ with_fileglob:
+ - "{{ role_path }}/templates/all/cron/*.j2"
+ - "{{ role_path }}/templates/{{ inventory_hostname }}/cron/*.j2"
diff --git a/roles/ands_scripts/templates/all/cron/maintain.j2 b/roles/ands_scripts/templates/all/cron/maintain.j2
new file mode 100644
index 0000000..fdd4231
--- /dev/null
+++ b/roles/ands_scripts/templates/all/cron/maintain.j2
@@ -0,0 +1,4 @@
+SHELL=/bin/bash
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+MAILTO=csa-darkserv@suren.me
+*/15 * * * * root {{ ands_script_path }}/subids.sh
diff --git a/roles/ands_scripts/templates/all/scripts/subids.sh b/roles/ands_scripts/templates/all/scripts/subids.sh
new file mode 100644
index 0000000..a83baa0
--- /dev/null
+++ b/roles/ands_scripts/templates/all/scripts/subids.sh
@@ -0,0 +1,19 @@
+#! /bin/bash
+
+[ -f /etc/subuid ] || exit
+[ -f /etc/subgid ] || exit
+
+users=$(getent group ipeusers | awk 'BEGIN { FS=":" } { print $4 }' | sed -e 's/,/\n/')
+subuid=$(cat /etc/subuid | awk 'BEGIN { FS=":" } { print $1 }')
+subgid=$(cat /etc/subgid | awk 'BEGIN { FS=":" } { print $1 }')
+
+subuid=$(echo -e "$users\n$subuid\n$subuid" | sort | uniq -u)
+subgid=$(echo -e "$users\n$subgid\n$subgid" | sort | uniq -u)
+
+for user in $subuid; do
+ grep -qxF "$user" /etc/subuid || sed -i'' -e "\$a$user:100000:65536" /etc/subuid
+done
+
+for user in $subgid; do
+ grep -qxF "$user" /etc/subgid || sed -i'' -e "\$a$user:100000:65536" /etc/subgid
+done