From a635d43f38e03e8a7e0ca38f7e4b220702136dbb Mon Sep 17 00:00:00 2001
From: Lars Beckers <lars.beckers@rwth-aachen.de>
Date: Fri, 22 Sep 2017 00:12:37 +0200
Subject: [PATCH] baremetal: reworked role, added microcode, removed bond,
 split apcupsd

---
 .../files/apcupsd/config.py                   |  0
 .../files/apcupsd/ganeti-ups.py               |  0
 .../files/apcupsd/ganeti.py                   |  0
 .../files/apcupsd/gnt-ha-client.py            |  0
 .../files/apcupsd/gnt-ha-daemon.py            |  0
 .../files/apcupsd/killpower/portal            |  0
 .../files/apcupsd/killpower/rumo              |  0
 .../files/apcupsd/killpower/video-main        |  0
 .../files/apcupsd/onbattery/vm01              |  0
 .../files/apcupsd/onbattery/vm02              |  0
 .../files/apcupsd/vm-onbattery.py             |  0
 apcupsd/handlers/main.yml                     |  5 ++
 .../apcupsd.yml => apcupsd/tasks/main.yml     |  0
 .../templates/apcupsd.conf.j2                 |  0
 baremetal/handlers/main.yml                   |  9 +--
 baremetal/meta/main.yml                       |  4 -
 baremetal/tasks/bond.yml                      | 16 ----
 baremetal/tasks/lldpd.yml                     | 25 ------
 baremetal/tasks/main.yml                      | 78 ++++++++++++-------
 baremetal/templates/interfaces.j2             | 27 -------
 20 files changed, 57 insertions(+), 107 deletions(-)
 rename {baremetal => apcupsd}/files/apcupsd/config.py (100%)
 rename {baremetal => apcupsd}/files/apcupsd/ganeti-ups.py (100%)
 rename {baremetal => apcupsd}/files/apcupsd/ganeti.py (100%)
 rename {baremetal => apcupsd}/files/apcupsd/gnt-ha-client.py (100%)
 rename {baremetal => apcupsd}/files/apcupsd/gnt-ha-daemon.py (100%)
 rename {baremetal => apcupsd}/files/apcupsd/killpower/portal (100%)
 rename {baremetal => apcupsd}/files/apcupsd/killpower/rumo (100%)
 rename {baremetal => apcupsd}/files/apcupsd/killpower/video-main (100%)
 rename {baremetal => apcupsd}/files/apcupsd/onbattery/vm01 (100%)
 rename {baremetal => apcupsd}/files/apcupsd/onbattery/vm02 (100%)
 rename {baremetal => apcupsd}/files/apcupsd/vm-onbattery.py (100%)
 create mode 100644 apcupsd/handlers/main.yml
 rename baremetal/tasks/apcupsd.yml => apcupsd/tasks/main.yml (100%)
 rename {baremetal => apcupsd}/templates/apcupsd.conf.j2 (100%)
 delete mode 100644 baremetal/meta/main.yml
 delete mode 100644 baremetal/tasks/bond.yml
 delete mode 100644 baremetal/tasks/lldpd.yml
 delete mode 100644 baremetal/templates/interfaces.j2

diff --git a/baremetal/files/apcupsd/config.py b/apcupsd/files/apcupsd/config.py
similarity index 100%
rename from baremetal/files/apcupsd/config.py
rename to apcupsd/files/apcupsd/config.py
diff --git a/baremetal/files/apcupsd/ganeti-ups.py b/apcupsd/files/apcupsd/ganeti-ups.py
similarity index 100%
rename from baremetal/files/apcupsd/ganeti-ups.py
rename to apcupsd/files/apcupsd/ganeti-ups.py
diff --git a/baremetal/files/apcupsd/ganeti.py b/apcupsd/files/apcupsd/ganeti.py
similarity index 100%
rename from baremetal/files/apcupsd/ganeti.py
rename to apcupsd/files/apcupsd/ganeti.py
diff --git a/baremetal/files/apcupsd/gnt-ha-client.py b/apcupsd/files/apcupsd/gnt-ha-client.py
similarity index 100%
rename from baremetal/files/apcupsd/gnt-ha-client.py
rename to apcupsd/files/apcupsd/gnt-ha-client.py
diff --git a/baremetal/files/apcupsd/gnt-ha-daemon.py b/apcupsd/files/apcupsd/gnt-ha-daemon.py
similarity index 100%
rename from baremetal/files/apcupsd/gnt-ha-daemon.py
rename to apcupsd/files/apcupsd/gnt-ha-daemon.py
diff --git a/baremetal/files/apcupsd/killpower/portal b/apcupsd/files/apcupsd/killpower/portal
similarity index 100%
rename from baremetal/files/apcupsd/killpower/portal
rename to apcupsd/files/apcupsd/killpower/portal
diff --git a/baremetal/files/apcupsd/killpower/rumo b/apcupsd/files/apcupsd/killpower/rumo
similarity index 100%
rename from baremetal/files/apcupsd/killpower/rumo
rename to apcupsd/files/apcupsd/killpower/rumo
diff --git a/baremetal/files/apcupsd/killpower/video-main b/apcupsd/files/apcupsd/killpower/video-main
similarity index 100%
rename from baremetal/files/apcupsd/killpower/video-main
rename to apcupsd/files/apcupsd/killpower/video-main
diff --git a/baremetal/files/apcupsd/onbattery/vm01 b/apcupsd/files/apcupsd/onbattery/vm01
similarity index 100%
rename from baremetal/files/apcupsd/onbattery/vm01
rename to apcupsd/files/apcupsd/onbattery/vm01
diff --git a/baremetal/files/apcupsd/onbattery/vm02 b/apcupsd/files/apcupsd/onbattery/vm02
similarity index 100%
rename from baremetal/files/apcupsd/onbattery/vm02
rename to apcupsd/files/apcupsd/onbattery/vm02
diff --git a/baremetal/files/apcupsd/vm-onbattery.py b/apcupsd/files/apcupsd/vm-onbattery.py
similarity index 100%
rename from baremetal/files/apcupsd/vm-onbattery.py
rename to apcupsd/files/apcupsd/vm-onbattery.py
diff --git a/apcupsd/handlers/main.yml b/apcupsd/handlers/main.yml
new file mode 100644
index 0000000..1b6bc76
--- /dev/null
+++ b/apcupsd/handlers/main.yml
@@ -0,0 +1,5 @@
+---
+
+- name: restart apcupsd
+  service: name=apcupsd state=restarted
+
diff --git a/baremetal/tasks/apcupsd.yml b/apcupsd/tasks/main.yml
similarity index 100%
rename from baremetal/tasks/apcupsd.yml
rename to apcupsd/tasks/main.yml
diff --git a/baremetal/templates/apcupsd.conf.j2 b/apcupsd/templates/apcupsd.conf.j2
similarity index 100%
rename from baremetal/templates/apcupsd.conf.j2
rename to apcupsd/templates/apcupsd.conf.j2
diff --git a/baremetal/handlers/main.yml b/baremetal/handlers/main.yml
index ca1e968..bba3ef7 100644
--- a/baremetal/handlers/main.yml
+++ b/baremetal/handlers/main.yml
@@ -1,9 +1,8 @@
 ---
-# file: roles/baremetal/handlers/main.yml
+# file: baremetal/handlers/main.yml
 
 - name: restart lldpd
-  service: name=lldpd state=restarted
-
-- name: restart apcupsd
-  service: name=apcupsd state=restarted
+  service:
+    name: lldpd
+    state: restarted
 
diff --git a/baremetal/meta/main.yml b/baremetal/meta/main.yml
deleted file mode 100644
index b700983..0000000
--- a/baremetal/meta/main.yml
+++ /dev/null
@@ -1,4 +0,0 @@
----
-dependencies:
-  - { role: "zabbix-agent", when: "'zabbix-agent' in group_names"}
-
diff --git a/baremetal/tasks/bond.yml b/baremetal/tasks/bond.yml
deleted file mode 100644
index e64addd..0000000
--- a/baremetal/tasks/bond.yml
+++ /dev/null
@@ -1,16 +0,0 @@
----
-# file: roles/baremetal/tasks/bond.yml
-
-- name: ensure ifenslave is installed
-  apt: state=latest name=ifenslave
-  tags:
-    - bond
-    - packages
-
-#- name: ensure bonding is configured
-#  template: src=interfaces.j2 dest=/etc/network/interfaces owner=root group=root mode=0644
-#  when: "not 'vm' in ansible_hostname"
-#  tags:
-#    - bond
-#    - config
-
diff --git a/baremetal/tasks/lldpd.yml b/baremetal/tasks/lldpd.yml
deleted file mode 100644
index 8fc3c6f..0000000
--- a/baremetal/tasks/lldpd.yml
+++ /dev/null
@@ -1,25 +0,0 @@
----
-# file: roles/baremetal/tasks/lldpd.yml
-
-- name: ensure lldpd is installed
-  apt: state=latest name=lldpd
-  notify:
-    - restart lldpd
-  tags:
-    - lldpd
-    - packages
-
-- name: ensure lldpd is configured
-  copy: src=lldpd dest=/etc/default/lldpd owner=root group=root mode=0644
-  notify:
-    - restart lldpd
-  tags:
-    - lldpd
-    - config
-
-- name: ensure lldpd is enabled and running
-  service: name=lldpd state=running enabled=yes
-  tags:
-    - lldpd
-    - service
-
diff --git a/baremetal/tasks/main.yml b/baremetal/tasks/main.yml
index a9c2c50..59714ef 100644
--- a/baremetal/tasks/main.yml
+++ b/baremetal/tasks/main.yml
@@ -1,36 +1,54 @@
 ---
-# file: roles/baremetal/tasks/main.yml
+# file: baremetal/tasks/main.yml
 
-- include: apcupsd.yml
-- meta: flush_handlers
-- include: bond.yml
-- meta: flush_handlers
-- include: lldpd.yml
-- meta: flush_handlers
-- name: ensure packages for nagios on baremetal are installed
-  apt: name={{ item }} state=present
+- name: ensure baremetal-specific packages are installed
+  apt:
+    name: {{ item }}
+    state: installed
   with_items:
-  - lm-sensors
-  - hddtemp
+    - lldpd
+    - lm-sensors
+    - hddtemp
+    - smartmontools
+    - hdparm
   tags:
-  - packages
-  - nagios
-- name: ensure hardware-tools are installed
-  apt: name={{ item }} state=present
-  with_items:
-  - smartmontools
-  - hdparm
+    - baremetal
+    - packages
+
+- name: ensure lldpd is configured
+  copy:
+    src: lldpd
+    dest: /etc/default/lldpd
+    owner: root
+    group: root
+    mode: 0644
+  notify:
+    - restart lldpd
   tags:
-  - packages
-  - hardware-tools
+    - baremetal
 
-- name: ensure zabbix-smart-check is installed
-  apt: name={{ item }} state=present
-  with_items:
-  - zabbix-check-smart
-  - zabbix-check-disk-performance
-  when: "'zabbix-agent' in group_names"
-  tags: 
-  - packages
-  - hardware-tools
-  - chr
+- name: ensure lldpd is enabled and running
+  service:
+    name: lldpd
+    state: running
+    enabled: yes
+  tags:
+    - baremetal
+
+- name: ensure microcode updates are available (Intel)
+  apt:
+    name: intel-microcode
+    state: installed
+  when: ansible_processor[1] == 'GenuineIntel'
+  tags:
+    - baremetal
+    - packages
+
+- name: ensure microcode updates are available (AMD)
+  apt:
+    name: amd64-microcode
+    state: installed
+  when: ansible_processor[1] == 'AuthenticAMD'
+  tags:
+    - baremetal
+    - packages
diff --git a/baremetal/templates/interfaces.j2 b/baremetal/templates/interfaces.j2
deleted file mode 100644
index 595a46f..0000000
--- a/baremetal/templates/interfaces.j2
+++ /dev/null
@@ -1,27 +0,0 @@
-# This file describes the network interfaces available on your system
-# and how to activate them. For more information, see interfaces(5).
-
-source /etc/network/interfaces.d/*
-
-# The loopback network interface
-auto lo
-iface lo inet loopback
-{% if bond %}
-# The bond0
-auto lo bond0
-iface bond0 inet static 
-	address {{ ipaddr }}
-	netmask {{ netmask }}
-	gateway {{ gateway }}
-	slaves eth0 eth1
-	bond_mode 802.3ad
-	bond_xmit_hash_policy layer2+3
-
-{% else %}
-auto {{ interface }}
-iface {{ interface }} inet static
-	address {{ ipaddr }}
-	netmask {{ netmask }}
-	gateway {{ gateway }}
-{% endif %}
-
-- 
GitLab