Extract Virtual BMC tasks into a role

The role will:
* Install VBMC requirements in virtualenv
* Set up VBMC daemon
* Add domains to VBMC
This commit is contained in:
Will Miller 2018-08-28 15:13:31 +00:00
parent fb0a948950
commit b36f95a04f
8 changed files with 75 additions and 39 deletions

View File

@ -52,10 +52,12 @@
{{ hostvars['localhost'].allocations.result[inventory_hostname]
| default([]) }}
- hosts: localhost
tasks:
- include_tasks: virtualbmc.yml
- include_role:
name: virtualbmc
vars:
vms: >-
vbmc_libvirt_domains: >-
{{ hostvars['localhost'].allocations.result[inventory_hostname]
| default([]) }}
| default([]) | map(attribute='name') | list }}
vbmc_log_directory: "{{ log_directory }}"
vbmc_virtualenv_path: "{{ virtualenv_path }}"
vbmc_python_upper_contraints_url: "{{ python_upper_constraints_url }}"

View File

@ -12,7 +12,7 @@ virtualenv_path: "{{ '/'.join([ansible_env['HOME'], 'tenks-venv']) }}"
# The URL of the upper constraints file to pass to pip when installing Python
# packages.
python_upper_contraints_url: >-
python_upper_constraints_url: >-
https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt
# Naming scheme for bridges created by tenks for physical networks is
@ -36,13 +36,3 @@ veth_vm_source_suffix: '-tap'
# Directory in which to store Tenks logs.
log_directory: /var/log/tenks/
# The address on which VBMC will listen for IPMI traffic.
vbmc_ipmi_listen_address: 0.0.0.0
# The range of ports available for use by VBMC.
vbmc_ipmi_port_range_start: 6230
vbmc_ipmi_port_range_end: 6240
# The IPMI username that VBMC will use.
vbmc_ipmi_username: username
# The IPMI password that VBMC will use.
vbmc_ipmi_password: password

View File

@ -43,11 +43,3 @@
loop: "{{ physnet_mappings | dictsort }}"
loop_control:
index_var: idx
- name: Ensure Python requirements are installed
pip:
requirements: >-
{{ '/'.join([(playbook_dir | dirname), 'venv-requirements.txt']) }}
extra_args: >-
-c {{ python_upper_contraints_url }}
virtualenv: "{{ virtualenv_path }}"

View File

@ -0,0 +1,25 @@
Virtual BMC
===========
This role sets up Virtual BMC. It will configure the Virtual BMC daemon in
systemd, and add the specified domains to the daemon.
Requirements
------------
- systemd
Role Variables
--------------
- `vbmc_libvirt_domains`: A list of Libvirt domain names to be added to Virtual
BMC.
- `vbmc_ipmi_listen_address`: The address on which Virtual BMC will listen for
IPMI traffic.
- `vbmc_ipmi_port_range_start`, `vbmc_ipmi_port_range_end`: The range of ports
available for use by Virtual BMC.
- `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.
- `vbmc_virtualenv_path`: The path to the virtualenv in which to install
Virtual BMC.

View File

@ -0,0 +1,17 @@
---
# A list of Libvirt domain names to be added to VBMC.
vbmc_libvirt_domains: []
# The address on which VBMC will listen for IPMI traffic.
vbmc_ipmi_listen_address: 0.0.0.0
# The range of ports available for use by VBMC.
vbmc_ipmi_port_range_start: 6230
vbmc_ipmi_port_range_end: 6240
# The IPMI username that VBMC will use.
vbmc_ipmi_username: username
# The IPMI password that VBMC will use.
vbmc_ipmi_password: password
# The directory in which to store VBMC logs.
vbmc_log_directory:
# The path to the virtualenv in which to install Virtual BMC.
vbmc_virtualenv_path:

View File

@ -3,15 +3,15 @@
set_fact:
# vbmcd should already be running, so --no-daemon stops vbmc from spawning
# another instance of the daemon.
cmd: "'{{ virtualenv_path }}/bin/vbmc' --no-daemon"
log_arg: "--log-file '{{ log_directory }}/vbmc-{{ vm.name }}.log'"
cmd: "'{{ vbmc_virtualenv_path }}/bin/vbmc' --no-daemon"
log_arg: "--log-file '{{ vbmc_log_directory }}/vbmc-{{ domain }}.log'"
# Even if the VM is present in VBMC, we can't guarantee that it's configured
# correctly. It's easiest to delete and re-add it; this should involve minimal
# downtime.
- name: Ensure VM is stopped and deleted in VBMC
command: >-
{{ cmd }} {{ item }} '{{ vm.name }}' {{ log_arg }}
{{ cmd }} {{ item }} '{{ domain }}' {{ log_arg }}
loop:
- stop
- delete
@ -22,9 +22,9 @@
- "'No domain with matching name' not in res.stderr"
become: true
- name: Ensure VM is added to VBMC
- name: Ensure domain is added to VBMC
command: >-
{{ cmd }} add '{{ vm.name }}'
{{ cmd }} add '{{ domain }}'
--port {{ port }}
--username '{{ vbmc_ipmi_username }}'
--password '{{ vbmc_ipmi_password }}'
@ -34,5 +34,5 @@
- name: Ensure VM is started in VBMC
command: >
{{ cmd }} start '{{ vm.name }}' {{ log_arg }}
{{ cmd }} start '{{ domain }}' {{ log_arg }}
become: true

View File

@ -4,11 +4,21 @@
service: vbmcd
- name: Check that enough ports are available for Virtual BMC
fail: >
{{ vms | count }} VMs were specified to be created, but only
{{ vbmc_ipmi_port_range_end - vbmc_ipmi_port_range_start }} ports are
available for use by Virtual BMC.
when: (vms | count) > (vbmc_ipmi_port_range_end - vbmc_ipmi_port_range_start)
fail:
msg: >
{{ vbmc_libvirt_domains | count }} VMs were specified to be created, but
only {{ vbmc_ipmi_port_range_end - vbmc_ipmi_port_range_start }} ports
are available for use by Virtual BMC.
when: >-
(vbmc_libvirt_domains | count) >
(vbmc_ipmi_port_range_end - vbmc_ipmi_port_range_start)
- name: Ensure Python requirements are installed
pip:
requirements: "{{ '/'.join([role_path, 'files', 'requirements.txt']) }}"
extra_args: >-
-c {{ vbmc_python_upper_contraints_url }}
virtualenv: "{{ vbmc_virtualenv_path }}"
- name: Ensure Virtual BMC systemd service is configured
template:
@ -30,11 +40,11 @@
daemon_reload: "{{ vbmc_service_file.changed }}"
become: true
- include_tasks: vm_virtualbmc.yml
- include_tasks: domain.yml
vars:
vm: "{{ vm }}"
domain: "{{ domain }}"
port: "{{ vbmc_ipmi_port_range_start + port_offset }}"
loop: "{{ vms }}"
loop: "{{ vbmc_libvirt_domains }}"
loop_control:
loop_var: vm
loop_var: domain
index_var: port_offset