kayobe/ansible/baremetal-compute-serial-console.yml
Mark Goddard b9d76f6ef5 Remove support for CentOS 7 and Python 2
* Always use Python 3
* Drop code paths for CentOS 7
* Drop support for Yum
* Remove support for host NTP daemon, always use chrony
* Switch references from 'yum_install_epel' to 'dnf_install_epel'
* Remove overcloud host image workaround for tagged VLAN admin network
* Remove the kayobe.utils.yum_install function, which is unused

Change-Id: I368f6edafed9779658798fc342116b4c1b3ffd48
Story: 2006574
Task: 39481
2020-05-28 10:25:51 +01:00

133 lines
5.4 KiB
YAML

---
# This playbook will enable a serial console on all ironic nodes. This
# will allow you to access the serial console from within Horizon.
# See: https://docs.openstack.org/ironic/latest/admin/console.html
- name: Setup OpenStack Environment
hosts: controllers[0]
gather_facts: False
vars:
venv: "{{ virtualenv_path }}/openstack-cli"
pre_tasks:
- name: Set up openstack cli virtualenv
pip:
virtualenv: "{{ venv }}"
name:
- python-openstackclient
- python-ironicclient
state: latest
extra_args: "{% if pip_upper_constraints_file %}-c {{ pip_upper_constraints_file }}{% endif %}"
- block:
- name: Fail if allocation pool start not defined
fail:
msg: >
The variable, ironic_serial_console_tcp_pool_start is not defined.
This variable is required to run this playbook.
when: not ironic_serial_console_tcp_pool_start
- name: Fail if allocation pool end not defined
fail:
msg: >
The variable, ironic_serial_console_tcp_pool_end is not defined.
This variable is required to run this playbook.
when:
- not ironic_serial_console_tcp_pool_end
- name: Get list of nodes that we should configure serial consoles on
set_fact:
baremetal_nodes: >-
{{ query('inventory_hostnames', console_compute_node_limit |
default('baremetal-compute') ) | unique }}
- name: Reserve TCP ports for ironic serial consoles
include_role:
name: console-allocation
vars:
console_allocation_pool_start: "{{ ironic_serial_console_tcp_pool_start }}"
console_allocation_pool_end: "{{ ironic_serial_console_tcp_pool_end }}"
console_allocation_ironic_nodes: "{{ baremetal_nodes }}"
console_allocation_filename: "{{ kayobe_config_path }}/console-allocation.yml"
when: cmd == "enable"
- name: Enable serial console
hosts: "{{ console_compute_node_limit | default('baremetal-compute') }}"
gather_facts: False
vars:
venv: "{{ virtualenv_path }}/openstack-cli"
controller_host: "{{ groups['controllers'][0] }}"
tasks:
- name: Get list of nodes
command: >
{{ venv }}/bin/openstack baremetal node list -f json --long
register: nodes
delegate_to: "{{ controller_host }}"
environment: "{{ openstack_auth_env }}"
run_once: true
changed_when: false
vars:
# NOTE: Without this, the controller's ansible_host variable will not
# be respected when using delegate_to.
ansible_host: "{{ hostvars[controller_host].ansible_host | default(controller_host) }}"
- block:
- name: Fail if console interface is not ipmitool-socat
fail:
msg: >-
In order to use the serial console you must set the console_interface to ipmitool-socat.
when: node["Console Interface"] != "ipmitool-socat"
- name: Set IPMI serial console terminal port
vars:
name: "{{ node['Name'] }}"
port: "{{ hostvars[controller_host].console_allocation_result.ports[name] }}"
# NOTE: Without this, the controller's ansible_host variable will not
# be respected when using delegate_to.
ansible_host: "{{ hostvars[controller_host].ansible_host | default(controller_host) }}"
command: >
{{ venv }}/bin/openstack baremetal node set {{ name }} --driver-info ipmi_terminal_port={{ port }}
delegate_to: "{{ controller_host }}"
environment: "{{ openstack_auth_env }}"
when: >-
node['Driver Info'].ipmi_terminal_port is not defined or
node['Driver Info'].ipmi_terminal_port | int != port | int
- name: Enable the IPMI socat serial console
vars:
# NOTE: Without this, the controller's ansible_host variable will not
# be respected when using delegate_to.
ansible_host: "{{ hostvars[controller_host].ansible_host | default(controller_host) }}"
command: >
{{ venv }}/bin/openstack baremetal node console enable {{ node['Name'] }}
delegate_to: "{{ controller_host }}"
environment: "{{ openstack_auth_env }}"
when: not node['Console Enabled']
vars:
matching_nodes: >-
{{ (nodes.stdout | from_json) | selectattr('Name', 'defined') |
selectattr('Name', 'equalto', inventory_hostname ) | list }}
node: "{{ matching_nodes | first }}"
when:
- cmd == "enable"
- matching_nodes | length > 0
- block:
- name: Disable the IPMI socat serial console
vars:
# NOTE: Without this, the controller's ansible_host variable will not
# be respected when using delegate_to.
ansible_host: "{{ hostvars[controller_host].ansible_host | default(controller_host) }}"
command: >
{{ venv }}/bin/openstack baremetal node console disable {{ node['Name'] }}
delegate_to: "{{ controller_host }}"
environment: "{{ openstack_auth_env }}"
when: node['Console Enabled']
vars:
matching_nodes: >-
{{ (nodes.stdout | from_json) | selectattr('Name', 'defined') |
selectattr('Name', 'equalto', inventory_hostname ) | list }}
node: "{{ matching_nodes | first }}"
when:
- cmd == "disable"
- matching_nodes | length > 0