[Baremetal] Add baremetal support to create-nodes 97/60797/35
authorManuel Buil <mbuil@suse.com>
Thu, 9 Aug 2018 14:52:46 +0000 (16:52 +0200)
committerManuel Buil <mbuil@suse.com>
Wed, 17 Oct 2018 15:18:51 +0000 (17:18 +0200)
Information about baremetal servers is collected for ironic to do
the provisioning. Two main things are done:

1 - baremetalhoststojson.yml fills the json config file fed to ironic
so that it knows how to boot the blades. In the baremetal case, the
create_vm.yml playbook will only create opnfv vm. The variable
vms_to_create holds that information. The variable baremetal_nodes
specifies the physical nodes (empty when non baremetal deployments)

2 - For PXE to work, we create a file called baremetalstaticips that
has the mapping between mac address from servers and its ip. That file
is moved into the dnsmasq config directory

Change-Id: I0e788db1deb50769c183b71524a68ac0b925f8aa
Signed-off-by: Manuel Buil <mbuil@suse.com>
xci/infra/bifrost/playbooks/xci-prepare-env.yml
xci/infra/bifrost/playbooks/xci-setup-nodes.yml
xci/playbooks/roles/create-nodes/defaults/main.yml
xci/playbooks/roles/create-nodes/tasks/barematalhoststojson.yml [new file with mode: 0644]
xci/playbooks/roles/create-nodes/tasks/create_vm.yml
xci/playbooks/roles/create-nodes/tasks/main.yml

index b4ad8c0..d576324 100644 (file)
   vars_files:
     - "{{ xci_path }}/xci/var/opnfv.yml"
   tasks:
-    - name: Copy bifrost inventory file
-      copy:
-        src: /tmp/baremetal.json
-        dest: /tmp/baremetal.json
 
     - name: Configure SSH key for devuser
       user:
         state: directory
       become: yes
 
+    # Directory must exist before passing the static config
+    - name: "Setup Inventory DHCP Hosts Directory"
+      file:
+        path: "/etc/dnsmasq.d/bifrost.dhcp-hosts.d"
+        state: directory
+        owner: "root"
+        group: "root"
+        mode: 0755
+      become: yes
+
+    - name: Copy bifrost files
+      copy:
+        src: "{{ item.src }}"
+        dest: "{{ item.dst }}"
+      with_items:
+        - { src: '/tmp/baremetal.json', dst: '/tmp/baremetal.json' }
+        - { src: '/tmp/baremetalstaticips', dst: '/etc/dnsmasq.d/bifrost.dhcp-hosts.d/baremetalstaticips' }
+      become: yes
+
     - name: Copy original qcow2 image to OPNFV VM
       synchronize:
         src: "{{ xci_cache }}/{{ item }}"
           become: yes
           when: _resolv_conf_netconfig.stat.exists
       when: ansible_pkg_mgr == 'zypper'
+
+    #TODO: Find a way to do this with Ansible
+    - name: Make sure the default gateway is correct
+      shell: "ip route del default"
+      become: yes
+
+    #TODO: Find a way to do this with Ansible
+    - name: Make sure the default gateway is correct
+      shell: "ip route add default via {{ host_info[inventory_hostname].public.gateway }}"
+      become: yes
index aaa5099..a0f9215 100644 (file)
@@ -38,7 +38,8 @@
         state: started
         port: 22
         connect_timeout: 10
-        timeout: 180
+        timeout: 10180
+
     # No ansible module for brctl found
     - name: Add pxe interface to the bridge
       shell: "brctl addif {{ item.bridge }} {{ item.interface }}"
index b03f138..02a429c 100644 (file)
@@ -4,10 +4,10 @@ baremetal_json_file: '/tmp/baremetal.json'
 
 # We collect these parameters from the pdf
 vm_nic: "virtio"
-vm_groups: {}
-vm_default_groups: "{{ lookup('env', 'DEFAULT_HOST_GROUPS').split() | default(['baremetal'], true) }}"
 vm_disk_cache: unsafe
 node_names: "{{ lookup('env', 'NODE_NAMES').split() }}"
+node_groups: {}
+node_default_groups: "{{ lookup('env', 'DEFAULT_HOST_GROUPS').split() | default(['baremetal'], true) }}"
 
 network_bridge_admin: 'br-admin'
 network_bridge_mgmt: 'br-mgmt'
@@ -27,4 +27,6 @@ vm_libvirt_uri: "{{ lookup('env', 'LIBVIRT_CONNECT_URI') | default('qemu:///syst
 
 opnfv_image_path: "/var/lib/libvirt/images"
 
+vms_to_create: "{{ (baremetal | bool) | ternary([opnfv_vm_pdf], [opnfv_vm_pdf] + nodes) }}"
+baremetal_nodes: "{{ (baremetal | bool) | ternary(nodes, omit) }}"
 libvirt_networks: "{{ (baremetal | bool) | ternary([vm_network_admin,vm_network_mgmt],[vm_network_admin]) }}"
diff --git a/xci/playbooks/roles/create-nodes/tasks/barematalhoststojson.yml b/xci/playbooks/roles/create-nodes/tasks/barematalhoststojson.yml
new file mode 100644 (file)
index 0000000..070221f
--- /dev/null
@@ -0,0 +1,79 @@
+---
+# Copyright 2018, SUSE Linux GmbH
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This playbook builds the json file with information about the baremetal nodes
+# which is read by ironic to start the pxe booting
+
+
+- name: BAREMETAL - Create file for static ip
+  file:
+    path: /tmp/baremetalstaticips
+    state: touch
+    group: root
+    owner: root
+    mode: 0644
+
+- name: "Generating the json describing baremetal nodes"
+  block:
+
+  - set_fact:
+      host_group: "{{ node_default_groups }}"
+
+  - set_fact:
+      host_group: "{{ node_default_groups | union(node_groups[item.name]) }}"
+    when: node_groups[item.name] is defined
+
+  - name: BAREMETAL - Fetch the ip
+    set_fact:
+      admin_ip: "{{ item.interfaces[idf.net_config.admin.interface].address }}"
+
+  - name: BAREMETAL - Fetch the mac
+    set_fact:
+      admin_mac: "{{ item.interfaces[idf.net_config.admin.interface].mac_address }}"
+
+  - name: BAREMETAL - set the json entry for baremetal nodes
+    set_fact:
+      node_data:
+        name: "{{ item.name }}"
+        uuid: "{{ item.name | to_uuid }}"
+        host_groups: "{{ vm_host_group }}"
+        driver: "{{ vm_node_driver|default('ipmi') }}"
+        driver_info:
+          power:
+            ipmi_address: "{{ item.remote_management.address }}"
+            ipmi_port: "{{ virtual_ipmi_port| default('623') }}"
+            ipmi_username: "{{ item.remote_management.user }}"
+            ipmi_password: "{{ item.remote_management.pass }}"
+        nics:
+          - mac: "{{ admin_mac }}"
+        ansible_ssh_host: "{{ admin_ip }}"
+        ipv4_address: "{{ admin_ip }}"
+        properties:
+          cpu_arch: "{{ item.node.arch }}"
+          ram: "{{ item.node.memory.rstrip('G') }}"
+          cpus: "{{ item.node.cpus }}"
+          disk_size: "{{ item.disks[0].disk_capacity.rstrip('G') }}"
+
+  - name: BAREMETAL - Static ip config for dnsmasq
+    lineinfile:
+      path: /tmp/baremetalstaticips
+      state: present
+      line: '{{ admin_mac }},{{ admin_ip }}'
+
+  - name: BAREMETAL - add created node info
+    set_fact:
+      nodes_json_data: "{{ nodes_json_data | combine({item.name: node_data}) }}"
+
+  when: (num_nodes | int) > (nodes_json_data | length | int) + 1
index bca5b48..7e1a745 100644 (file)
@@ -6,11 +6,11 @@
 
   - set_fact:
       vm_log_file: "{{ node_logdir }}/{{ vm_name }}_console.log"
-      vm_host_group: "{{ vm_default_groups }}"
+      vm_host_group: "{{ node_default_groups }}"
 
   - set_fact:
-      vm_host_group: "{{ vm_default_groups | union(vm_groups[vm_name]) }}"
-    when: vm_groups[vm_name] is defined
+      vm_host_group: "{{ node_default_groups | union(node_groups[vm_name]) }}"
+    when: node_groups[vm_name] is defined
 
   - name: set prealloc arg for Debian
     set_fact:
index 18bc987..0e51b41 100644 (file)
 
 # First we create the opnfv_vm
 - include_tasks: create_vm.yml
-  with_indexed_items: "{{ [opnfv_vm_pdf] + nodes }}"
+  with_indexed_items: "{{ vms_to_create }}"
+
+- include_tasks: barematalhoststojson.yml
+  with_items: "{{ baremetal_nodes }}"
 
 - name: Start the opnfv vm
-  virt: 
+  virt:
     command: start
     name: opnfv
 
@@ -38,8 +41,6 @@
     dest: "{{ baremetal_json_file }}"
     content: "{{ nodes_json_data | to_nice_json }}"
 
-- debug: var=nodes_json_data
-
 - name: >
     "Set file permissions such that the baremetal data file
     can be read by the user executing Ansible"