Update enodebd role to support molecule testing
Change-Id: Ib98990d1ca572209db93099cfe3f0e1a40e59a04
diff --git a/tasks/Debian.yml b/tasks/Debian.yml
new file mode 100644
index 0000000..97c51c5
--- /dev/null
+++ b/tasks/Debian.yml
@@ -0,0 +1,24 @@
+---
+# enodebd tasks/Debian.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: Install enodebd Prereqs
+ apt:
+ name:
+ - "python3"
+ - "python3-pip"
+ state: "present"
+ update_cache: true
+ cache_valid_time: 3600
+
+- name: Create systemd service unit files for enodebd services
+ template:
+ src: "{{ item }}.j2"
+ dest: "/etc/systemd/system/{{ item }}"
+ owner: "root"
+ group: "root"
+ mode: "0644"
+ with_items:
+ - "enodebd.service"
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..033163b
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,93 @@
+---
+# netbox tasks/main.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: include OS-specific vars
+ include_vars: "{{ ansible_os_family }}.yml"
+
+- name: include OS-specific tasks
+ include_tasks: "{{ ansible_os_family }}.yml"
+
+- name: Create group for enodebd
+ group:
+ name: "{{ enodebd_groupname }}"
+
+- name: Create user for enodebd
+ user:
+ name: "{{ enodebd_username }}"
+ group: "{{ enodebd_groupname }}"
+ comment: "{{ enodebd_comment }}"
+ shell: "{{ enodebd_shell }}"
+ system: true
+ password_lock: true
+
+- name: Create enodebd dist dir
+ file:
+ path: "{{ enodebd_dist_dir }}"
+ state: directory
+ owner: "{{ enodebd_username }}"
+ group: "{{ enodebd_groupname }}"
+ mode: "0755"
+
+- name: Download enodebd distribution .tgz file
+ get_url:
+ url: "https://github.com/aweimeow/enodebd/archive/refs/tags/v{{ enodebd_version }}.tar.gz"
+ dest: "{{ enodebd_dist_dir }}/enodebd_v{{ enodebd_version }}.tar.gz"
+ owner: "{{ enodebd_username }}"
+ group: "{{ enodebd_groupname }}"
+ mode: "0644"
+ checksum: "{{ enodebd_version_checksum }}"
+
+- name: Unarchive enodebd distribution
+ unarchive:
+ remote_src: true
+ src: "{{ enodebd_dist_dir }}/enodebd_v{{ enodebd_version }}.tar.gz"
+ dest: "/opt"
+ owner: "{{ enodebd_username }}"
+ group: "{{ enodebd_groupname }}"
+ creates: "/opt/enodebd-{{ enodebd_version }}"
+
+- name: Link enodebd distro to working dir
+ file:
+ state: "link"
+ src: "/opt/enodebd-{{ enodebd_version }}"
+ dest: "{{ enodebd_working_dir }}"
+
+- name: Create enodebd virtual environment
+ command:
+ chdir: "{{ enodebd_working_dir }}"
+ cmd: "make venv"
+ creates: "/opt/enodebd-{{ enodebd_version }}/venv"
+
+- name: Install protobuf
+ command:
+ chdir: "{{ enodebd_working_dir }}"
+ cmd: "make install-protoc"
+ creates: "/opt/protobuf/bin/protoc"
+
+- name: Compile enodebd proto files
+ command:
+ chdir: "{{ enodebd_working_dir }}"
+ cmd: "make proto"
+ creates: "/opt/enodebd-{{ enodebd_version }}/metrics_pb2.py"
+
+- name: Create enodebd.yml configuration
+ template:
+ src: "{{ item }}.j2"
+ dest: "{{ enodebd_working_dir }}/magma_configs/enodebd.yml"
+ owner: "{{ enodebd_username }}"
+ group: "{{ enodebd_groupname }}"
+ mode: "0644"
+ force: false
+ with_items:
+ - "enodebd.yml"
+
+- name: Start enodebd
+ service:
+ name: "{{ item }}"
+ state: "started"
+ enabled: true
+ with_items:
+ - "enodebd"