From 2d214adef32fdc3dc690397ed0e5b5e92c7f64a9 Mon Sep 17 00:00:00 2001
From: Will Miller <willm@stackhpc.com>
Date: Thu, 30 Aug 2018 11:29:49 +0000
Subject: [PATCH] Extract IPMI configuration out of role

This is required for Ironic enrolment as well as Virtual BMC
configuration.
---
 ansible/deploy.yml                                |  8 +++++---
 ansible/group_vars/hypervisors                    | 10 ++++++++++
 ansible/group_vars/libvirt                        |  4 ----
 ansible/roles/virtualbmc-domain/README.md         | 13 +++++--------
 ansible/roles/virtualbmc-domain/defaults/main.yml |  9 ++++-----
 ansible/roles/virtualbmc-domain/tasks/main.yml    |  4 ++--
 6 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/ansible/deploy.yml b/ansible/deploy.yml
index e3242f6..61c438a 100644
--- a/ansible/deploy.yml
+++ b/ansible/deploy.yml
@@ -40,14 +40,13 @@
       # Loop over each physical network for each node allocated to this host.
       # Allocations are stored in localhost's vars.
       loop: >-
-        {{ hostvars['localhost'].allocations.result[inventory_hostname]
+        {{ hostvars.localhost.allocations.result[inventory_hostname]
              | default([]) | subelements('physical_networks') }}
 
 - hosts: libvirt
   vars:
-    # Allocations are stored in the localhost's vars.
     nodes: >-
-      {{ hostvars['localhost'].allocations.result[inventory_hostname]
+      {{ hostvars.localhost.allocations.result[inventory_hostname]
            | default([]) }}
   tasks:
     - name: Create Libvirt VMs
@@ -77,6 +76,9 @@
         name: virtualbmc-domain
       vars:
         vbmc_domain: "{{ domain }}"
+        vbmc_ipmi_address: "{{ ipmi_address }}"
+        vbmc_ipmi_username: "{{ ipmi_username }}"
+        vbmc_ipmi_password: "{{ ipmi_password }}"
         vbmc_ipmi_port: "{{ ipmi_port_range_start + port_offset }}"
         vbmc_virtualenv_path: "{{ virtualenv_path }}"
         vbmc_log_directory: "{{ log_directory }}"
diff --git a/ansible/group_vars/hypervisors b/ansible/group_vars/hypervisors
index 5cc26a7..4b7eb96 100644
--- a/ansible/group_vars/hypervisors
+++ b/ansible/group_vars/hypervisors
@@ -36,3 +36,13 @@ veth_node_source_suffix: '-tap'
 
 # Directory in which to store Tenks logs.
 log_directory: /var/log/tenks/
+
+# The address on which VBMC will listen for node IPMI communication.
+ipmi_address: 0.0.0.0
+# The range of ports available for use for node IPMI communication.
+ipmi_port_range_start: 6230
+ipmi_port_range_end: 6240
+# The username to use for node IPMI communication.
+ipmi_username: username
+# The password to use for node IPMI communication.
+ipmi_password: password
diff --git a/ansible/group_vars/libvirt b/ansible/group_vars/libvirt
index 0e797d2..694a712 100644
--- a/ansible/group_vars/libvirt
+++ b/ansible/group_vars/libvirt
@@ -11,7 +11,3 @@ libvirt_pool_group: "{{ ansible_user_id }}"
 # By default, allow QEMU without hardware virtualisation since this is a
 # development tool.
 libvirt_require_vt: false
-
-# The range of ports available for use for node IPMI traffic.
-ipmi_port_range_start: 6230
-ipmi_port_range_end: 6240
diff --git a/ansible/roles/virtualbmc-domain/README.md b/ansible/roles/virtualbmc-domain/README.md
index 9ce0236..06f4d2f 100644
--- a/ansible/roles/virtualbmc-domain/README.md
+++ b/ansible/roles/virtualbmc-domain/README.md
@@ -15,13 +15,10 @@ Role Variables
 - `vbmc_domain`: The name of the Libvirt domain to be added to Virtual BMC.
 - `vbmc_virtualenv_path`: The path to the virtualenv in which Virtual BMC is
   installed.
-- `vbmc_ipmi_listen_address`: The address on which Virtual BMC will listen for
-  IPMI traffic. Default is 0.0.0.0.
+- `vbmc_ipmi_address`: The address on which Virtual BMC will listen for IPMI
+  traffic.
 - `vbmc_ipmi_port`: The port on which Virtual BMC will listen for IPMI traffic.
-  Default is 6230.
-- `vbmc_ipmi_username`: The IPMI username that Virtual BMC will use. Default is
-  'username'.
-- `vbmc_ipmi_password`: The IPMI password that Virtual BMC will use. Default is
-  'password'.
+- `vbmc_ipmi_username`: The IPMI username that Virtual BMC will use.
+- `vbmc_ipmi_password`: The IPMI password that Virtual BMC will use.
 - `vbmc_log_directory`: The directory in which to store Virtual BMC logs. If
-   `None`, output will not be logged to a file. Default is `None`.
+   not overridden from `None`, output will not be logged to a file.
diff --git a/ansible/roles/virtualbmc-domain/defaults/main.yml b/ansible/roles/virtualbmc-domain/defaults/main.yml
index 25f4416..a2951e3 100644
--- a/ansible/roles/virtualbmc-domain/defaults/main.yml
+++ b/ansible/roles/virtualbmc-domain/defaults/main.yml
@@ -1,13 +1,12 @@
 ---
 # The address on which VBMC will listen for IPMI traffic for this domain.
-vbmc_ipmi_listen_address: 0.0.0.0
+vbmc_listen_address:
 # The port on which VBMC will listen for IPMI traffic for this domain.
-vbmc_ipmi_port: 6230
+vbmc_ipmi_port:
 # The IPMI username that VBMC will use.
-vbmc_ipmi_username: username
+vbmc_ipmi_username:
 # The IPMI password that VBMC will use.
-vbmc_ipmi_password: password
-
+vbmc_ipmi_password:
 # The name of the Libvirt domain to be added to Virtual BMC.
 vbmc_domain:
 # The directory in which to store VBMC logs.
diff --git a/ansible/roles/virtualbmc-domain/tasks/main.yml b/ansible/roles/virtualbmc-domain/tasks/main.yml
index 4873ea7..d2c93bd 100644
--- a/ansible/roles/virtualbmc-domain/tasks/main.yml
+++ b/ansible/roles/virtualbmc-domain/tasks/main.yml
@@ -30,7 +30,7 @@
 # Check here to be safe.
 - name: Wait to ensure socket is closed
   wait_for:
-    host: "{{ vbmc_ipmi_listen_address }}"
+    host: "{{ vbmc_ipmi_address }}"
     port: "{{ vbmc_ipmi_port }}"
     state: stopped
     timeout: 15
@@ -41,7 +41,7 @@
       --port {{ vbmc_ipmi_port }}
       --username '{{ vbmc_ipmi_username }}'
       --password '{{ vbmc_ipmi_password }}'
-      --address {{ vbmc_ipmi_listen_address }}
+      --address {{ vbmc_ipmi_address }}
   become: true
 
 - name: Ensure domain is started in VBMC