From 29e5c9cd1dac0bc1193449b8bd565ccc3a6f7a95 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Wed, 26 Apr 2017 15:33:48 +0100 Subject: [PATCH] Factor out compute node inventory generation into a separate playbook --- ansible/compute-node-discovery.yml | 27 +--------------- ansible/dell-compute-node-boot-mode.yml | 39 +++-------------------- ansible/dell-compute-node-discovery.yml | 41 +++++-------------------- ansible/dell-compute-node-inventory.yml | 25 +++++++++++++++ 4 files changed, 38 insertions(+), 94 deletions(-) create mode 100644 ansible/dell-compute-node-inventory.yml diff --git a/ansible/compute-node-discovery.yml b/ansible/compute-node-discovery.yml index 51154757e..3d00efd87 100644 --- a/ansible/compute-node-discovery.yml +++ b/ansible/compute-node-discovery.yml @@ -1,24 +1,5 @@ --- -- name: Ensure compute nodes are present in the Ansible inventory - hosts: config-mgmt - gather_facts: no - vars: - # Set this to a colon-separated list of compute node hostnames on which to - # trigger discovery. If unset, all compute nodes will be triggered. - compute_node_limit: - compute_node_limit_list: "{{ compute_node_limit.split(':') }}" - tasks: - - name: Add hosts for the compute nodes - add_host: - name: "{{ item.key }}" - groups: compute - with_dict: "{{ idrac_network_ips }}" - # Don't add hosts that already exist. - when: - - "{{ item.key not in groups['all'] }}" - - "{{ item.key | replace('-idrac', '') not in groups['all'] }}" - - "{{ not compute_node_limit or item.key | replace('-idrac', '') in compute_node_limit_list }}" - run_once: True +- include: dell-compute-node-inventory.yml - name: Ensure compute nodes are PXE booted hosts: compute @@ -36,12 +17,6 @@ with_items: - "{{ hostvars[delegate_host].ansible_host }}" - - name: Set a fact containing the compute node IPMI address - set_fact: - ipmi_username: "{{ inspector_ipmi_username }}" - ipmi_password: "{{ inspector_ipmi_password }}" - ipmi_address: "{{ idrac_network_ips[inventory_hostname] }}" - - name: Ensure compute nodes are powered off command: ipmitool -U {{ ipmi_username }} -P {{ ipmi_password }} -H {{ ipmi_address }} -I lanplus chassis power off delegate_to: "{{ item }}" diff --git a/ansible/dell-compute-node-boot-mode.yml b/ansible/dell-compute-node-boot-mode.yml index 37564df2e..fe4bdbd87 100644 --- a/ansible/dell-compute-node-boot-mode.yml +++ b/ansible/dell-compute-node-boot-mode.yml @@ -1,26 +1,8 @@ --- # Set the boot mode (BIOS, UEFI) of Dell compute nodes. -- name: Ensure compute nodes are present in the Ansible inventory - hosts: config-mgmt - gather_facts: no - vars: - # Set this to a colon-separated list of compute node hostnames on which to - # set the boot mode. If unset, all compute nodes will be set. - compute_node_limit: "" - compute_node_limit_list: "{{ compute_node_limit.split(':') }}" - tasks: - - name: Add hosts for the compute nodes - add_host: - name: "{{ item.key }}" - groups: compute - with_dict: "{{ idrac_network_ips }}" - # Don't add hosts that already exist. - when: - - "{{ item.key not in groups['all'] }}" - - "{{ item.key | replace('-idrac', '') not in groups['all'] }}" - - "{{ not compute_node_limit or item.key | replace('-idrac', '') in compute_node_limit_list }}" - run_once: True +# Add compute nodes to the Ansible inventory. +- include: dell-compute-node-boot-mode.yml - name: Ensure compute nodes boot mode is set hosts: compute @@ -28,17 +10,6 @@ vars: # Set this to the required boot mode. One of 'bios' or 'uefi'. drac_boot_mode: "bios" - tasks: - - name: Set a fact containing the compute node IPMI address - set_fact: - ansible_host: "{{ idrac_network_ips[inventory_hostname] }}" - ansible_user: "{{ ipmi_username }}" - ansible_ssh_pass: "{{ ipmi_password }}" - - - name: Ensure the compute node's BMC is added as an SSH known host - include_role: - role: ssh-known-host - - - name: Ensure the compute node's boot mode is set - include_role: - role: drac-boot-mode + roles: + - role: ssh-known-host + - role: drac-boot-mode diff --git a/ansible/dell-compute-node-discovery.yml b/ansible/dell-compute-node-discovery.yml index 289b9274e..597e641fe 100644 --- a/ansible/dell-compute-node-discovery.yml +++ b/ansible/dell-compute-node-discovery.yml @@ -1,24 +1,8 @@ --- -- name: Ensure compute nodes are present in the Ansible inventory - hosts: config-mgmt - gather_facts: no - vars: - # Set this to a colon-separated list of compute node hostnames on which to - # trigger discovery. If unset, all compute nodes will be triggered. - compute_node_limit: "" - compute_node_limit_list: "{{ compute_node_limit.split(':') }}" - tasks: - - name: Add hosts for the compute nodes - add_host: - name: "{{ item.key }}" - groups: compute - with_dict: "{{ idrac_network_ips }}" - # Don't add hosts that already exist. - when: - - "{{ item.key not in groups['all'] }}" - - "{{ item.key | replace('-idrac', '') not in groups['all'] }}" - - "{{ not compute_node_limit or item.key | replace('-idrac', '') in compute_node_limit_list }}" - run_once: True +# Configure the compute nodes to PXE boot. + +# Add compute nodes to the Ansible inventory. +- include: dell-compute-node-inventory.yml - name: Ensure compute nodes are PXE booted hosts: compute @@ -28,17 +12,6 @@ drac_pxe_interface: 1 # Set this to a list of indices of all interfaces. drac_pxe_all_interfaces: [1, 2, 3, 4] - tasks: - - name: Set a fact containing the compute node IPMI address - set_fact: - ansible_host: "{{ idrac_network_ips[inventory_hostname] }}" - ansible_user: "{{ ipmi_username }}" - ansible_ssh_pass: "{{ ipmi_password }}" - - - name: Ensure the compute node's BMC is added as a known host - include_role: - role: ssh-known-host - - - name: Ensure the compute node's BMC is set to PXE boot - include_role: - role: drac-pxe + roles: + - role: ssh-known-host + - role: drac-pxe diff --git a/ansible/dell-compute-node-inventory.yml b/ansible/dell-compute-node-inventory.yml new file mode 100644 index 000000000..23ddac212 --- /dev/null +++ b/ansible/dell-compute-node-inventory.yml @@ -0,0 +1,25 @@ +--- +- name: Ensure compute nodes are present in the Ansible inventory + hosts: config-mgmt + gather_facts: no + vars: + # Set this to a colon-separated list of compute node hostnames on which to + # trigger discovery. If unset, all compute nodes will be triggered. + compute_node_limit: "" + compute_node_limit_list: "{{ compute_node_limit.split(':') }}" + tasks: + - name: Add hosts for the compute nodes + add_host: + name: "{{ item.key }}" + groups: compute + # SSH configuration to access the BMC. + ansible_host: "{{ item.value }}" + ansible_user: "{{ ipmi_username }}" + ansible_ssh_pass: "{{ ipmi_password }}" + with_dict: "{{ idrac_network_ips }}" + # Don't add hosts that already exist. + when: + - "{{ item.key not in groups['all'] }}" + - "{{ item.key | replace('-idrac', '') not in groups['all'] }}" + - "{{ not compute_node_limit or item.key | replace('-idrac', '') in compute_node_limit_list }}" + run_once: True