Kaynağa Gözat

Merge branch 'devel' into offline_repo

John Lockman 3 yıl önce
ebeveyn
işleme
c69ab3632e

+ 8 - 10
control_plane/roles/control_plane_device/files/Dockerfile

@@ -1,23 +1,21 @@
 # Dockerfile for creating the management network container
 
-FROM centos:7
+FROM centos:8
 
 # RPM REPOs
-RUN yum install -y \
+RUN dnf install -y \
     epel-release \
-    && yum clean all \
-    && rm -rf /var/cache/yum
+    && dnf clean all \
+    && rm -rf /var/cache/dnf
 
-RUN yum update -y \
-    && yum clean all \
-    && rm -rf /var/cache/yum
+RUN dnf install -y dhcp-server
+RUN dnf install -y python3-netaddr
 
 RUN yum install -y \
   ansible \
   cronie \
   tftp\
   tftp-server\
-  dhcp \
   xinetd \
   net-tools \
   && yum clean all \
@@ -28,10 +26,10 @@ RUN mkdir /root/omnia
 #Copy Configuration files
 COPY dhcpd.conf  /etc/dhcp/dhcpd.conf
 COPY tftp /etc/xinetd.d/tftp
+COPY inventory_creation.yml /root/
 COPY mngmnt_container_configure.yml /root/
 
 RUN systemctl enable tftp
 RUN systemctl enable dhcpd
 
-CMD ["sbin/init"]
-
+CMD ["sbin/init"]

+ 0 - 48
control_plane/roles/control_plane_device/files/dhcpd.conf

@@ -1,48 +0,0 @@
-
-# ******************************************************************
-# Cobbler managed dhcpd.conf file
-#
-# generated from cobbler dhcp.conf template ($date)
-# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
-# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
-# overwritten.
-#
-# ******************************************************************
-
-ddns-update-style interim;
-
-allow booting;
-allow bootp;
-
-ignore client-updates;
-set vendorclass = option vendor-class-identifier;
-
-option pxe-system-type code 93 = unsigned integer 16;
-
-subnet 172.17.0.0 netmask 255.255.0.0 {
-option subnet-mask 255.255.0.0;
-range dynamic-bootp 172.17.0.10 172.17.0.100;
-default-lease-time  21600;
-max-lease-time  43200;
-next-server 172.17.0.1;
-#insert the static DHCP leases for configuration here
-
-
-     class "pxeclients" {
-          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
-          if option pxe-system-type = 00:02 {
-                  filename "ia64/elilo.efi";
-          } else if option pxe-system-type = 00:06 {
-                  filename "grub/grub-x86.efi";
-          } else if option pxe-system-type = 00:07 {
-                  filename "grub/grub-x86_64.efi";
-          } else if option pxe-system-type = 00:09 {
-                  filename "grub/grub-x86_64.efi";
-          } else {
-                  filename "pxelinux.0";
-          }
-     }
-
-}
-
-#end for

+ 53 - 0
control_plane/roles/control_plane_device/files/inventory_creation.yml

@@ -0,0 +1,53 @@
+#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  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.
+---
+
+- hosts: localhost
+  connection: local
+  gather_facts: false
+  tasks:
+    - name: Read dhcp file
+      set_fact:
+        var: "{{ lookup('file', '/var/lib/dhcpd/dhcpd.leases').split()| unique | select| list }}"
+
+    - name: Filter the ip
+      set_fact:
+        vars_new: "{{ var| ipv4('address')| to_nice_yaml}}"
+
+    - name: Create the static ip
+      shell: awk -F',' 'NR >1{print $2}' /root/omnia/control_plane/roles/control_plane_device/files/new_mngmnt_mapping_file.csv > static_hosts.yml
+      changed_when: false
+      failed_when: false
+
+    - name: Create the dynamic inventory
+      shell: |
+        echo "{{ vars_new }}" > temp.txt
+        egrep -o '[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' temp.txt >>dynamic_hosts.yml
+      changed_when: false
+      failed_when: false
+
+    - name: Final inventory
+      shell: cat dynamic_hosts.yml static_hosts.yml| sort -ur  >> omnia/control_plane/roles/collect_device_info/files/mgmt_provisioned_hosts.yml
+      changed_when: false
+
+    - name: Temp result
+      shell: cat /root/omnia/control_plane/roles/collect_device_info/files/mgmt_provisioned_hosts.yml |sort|uniq
+      register: inventory
+
+    - name: Final Inventory
+      local_action: copy content="{{ inventory.stdout }}" dest=omnia/control_plane/roles/collect_device_info/files/mgmt_provisioned_hosts.yml
+
+    - name: New line at end of file
+      shell: echo "">> omnia/control_plane/roles/collect_device_info/files/mgmt_provisioned_hosts.yml
+      changed_when: false

+ 1 - 1
control_plane/roles/control_plane_device/files/k8s_mngmnt_network.yml

@@ -33,4 +33,4 @@ spec:
             - name: omnia-storage
               mountPath: /root/omnia
           securityContext:
-            privileged: true
+            privileged: true

+ 12 - 1
control_plane/roles/control_plane_device/files/mngmnt_container_configure.yml

@@ -67,4 +67,15 @@
   - name: Start dhcpd services
     service:
       name: dhcpd
-      state: started
+      state: started
+
+  - name: Fetch ansible-playbook location
+    command: whereis ansible-playbook
+    changed_when: false
+    register: ansible_playbook_location
+
+  - name: Add inventory cron job
+    cron:
+      name: Create inventory
+      minute: "*/5"
+      job: "{{ ansible_playbook_location.stdout.split(' ')[1] }} /root/inventory_creation.yml"

+ 0 - 23
control_plane/roles/control_plane_device/files/start_mngmnt_container.yml

@@ -1,23 +0,0 @@
-#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
-#
-#  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.
----
-
-- name: Start mngmnt_network on reboot
-  hosts: localhost
-  connection: local
-  gather_facts: false
-  tasks:
-    - name: Wait for 2 minutes
-      pause:
-        minutes: 2

+ 1 - 2
control_plane/roles/control_plane_device/files/temp_dhcp.template

@@ -1,4 +1,3 @@
-
 # ******************************************************************
 # Cobbler managed dhcpd.conf file
 #
@@ -45,4 +44,4 @@ next-server next_server;
 
 }
 
-#end for
+#end for

+ 9 - 16
control_plane/roles/control_plane_device/tasks/check_prerequisites.yml

@@ -8,7 +8,7 @@
 #
 # 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.
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIiND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ---
@@ -17,22 +17,21 @@
   set_fact:
     mngmnt_network_container_status: false
     mngmnt_network_container_image_status: false
-    mngmnt_network_container_config_status: false
-    backup_map_status: false
-    new_node_status: false
+    backup_mngmnt_map_status: false
+    new_mngmnt_node_status: false
   tags: install
 
 - name: Check if any backup file exists
   block:
   - name: Check status of backup file
     stat:
-      path: "{{ role_path }}/files/backup_mapping_file.csv"
-    register: backup_map
+      path: "{{ role_path }}/files/backup_mngmnt_mapping_file.csv"
+    register: backup_mngmnt_map
 
   - name: Set status for backup file
     set_fact:
-      backup_map_status: true
-    when: backup_map.stat.exists == true  
+      backup_mngmnt_map_status: true
+    when: backup_mngmnt_map.stat.exists
   rescue:
   - name: Message
     debug:
@@ -42,14 +41,14 @@
 - name: Inspect the mngmnt_network_container image
   command: "buildah images {{ mngmnt_network_image_name }}"
   register: mngmnt_network_container_image_result
-  ignore_errors: true
+  failed_when: false
   changed_when: false
   tags: install
 
 - name: Check mngmnt_network_container status on the machine
   command: kubectl get pods -n network-config
   register: mngmnt_network_container_result
-  ignore_errors: true
+  failed_when: false
   changed_when: false
   tags: install
 
@@ -64,9 +63,3 @@
     mngmnt_network_container_status: true
   when: "'mngmnt-network-container' in mngmnt_network_container_result.stdout"
   tags: install
-
-- name: Update mngmnt_network_container  status
-  set_fact:
-    mngmnt_network_container_config_status: true
-  when:
-    - mngmnt_network_container_status == true

+ 10 - 16
control_plane/roles/control_plane_device/tasks/configure_mngmnt_network_container.yml

@@ -17,13 +17,7 @@
   command: kubectl get pods -n network-config
   changed_when: false
   register: mngmnt_network_pod_status
-  ignore_errors: true
-
-- name: Deploy mngmnt_network pod
-  command: "kubectl apply -f {{ role_path }}/files/k8s_mngmnt_network.yml"
-  changed_when: true
-  tags: install
-  when: mngmnt_network_container_status == true and  mngmnt_network_container_config_status == false
+  failed_when: false
 
 - name: Wait for mngmnt_network pod to come to ready state
   command: kubectl wait --for=condition=ready -n network-config pod -l app=mngmnt-network
@@ -38,15 +32,15 @@
 
 - name: Configuring mngmnt_network container
   command: 'kubectl exec --stdin --tty -n network-config {{ mngmnt_network_pod_name.stdout }} \
-    -- ansible-playbook /root/omnia/control_plane/roles/control_plane_device/files/mngmnt_container_configure.yml'
+    -- ansible-playbook /root/mngmnt_container_configure.yml'
   changed_when: false
   tags: install
-  when: mngmnt_network_container_config_status == false
+  when: not mngmnt_network_container_status
 
-- name: Schedule task
-  cron:
-    name: "start mngmnt_network_container on reboot"
-    special_time: reboot
-    job: "ansible-playbook {{ role_path }}/files/start_mngmnt_container.yml"
-  tags: install
-  #when: mngmnt_network_container_config_status == false
+- name: Remove the files
+  file:
+    path: "{{ item }}"
+    state: absent
+  with_items:
+    - "{{ role_path }}/files/dhcpd.conf"
+    - "{{ role_path }}/files/temp_mgmt_mapping_file.csv.bak"

+ 9 - 11
control_plane/roles/control_plane_device/tasks/main.yml

@@ -31,19 +31,15 @@
   when: not mngmnt_network_container_status
 
 - name: Include variable file base_vars.yml
-  include_vars: "{{ mngmnt_base_file }}"
-
-#- name: Fetch base inputs
-#  include_tasks: ../../control_plane_common/tasks/fetch_base_inputs.yml
-#  when: not mngmnt_network_container_status
+  include_vars: "{{ base_mngmnt_file }}"
 
 - name: Dhcp Configuration
   import_tasks: dhcp_configure.yml
-  when: (not mngmnt_network_container_image_status) or ( backup_map_status == true)
+  when: (not mngmnt_network_container_image_status) or ( backup_mngmnt_map_status)
 
-#- name: Mapping file validation
-#  import_tasks: mapping_file.yml
-#  when: (not mngmnt_network_container_image_status) and (mapping_file == true) or ( backup_map_status == true)
+- name: Mapping file validation
+  import_tasks: mapping_file.yml
+  when: (not mngmnt_network_container_image_status) and (mngmnt_mapping_file_path) or ( backup_mngmnt_map_status)
 
 - name: mngmnt_network_container image creation
   import_tasks: mngmnt_network_container_image.yml
@@ -54,11 +50,13 @@
 
 - name: mngmnt_network_container container status message
   block:
-    - debug:
+    - name: management network container running
+      debug:
         msg: "{{ message_skipped }}"
         verbosity: 2
       when: mngmnt_network_container_status
-    - debug:
+    - name: management network container not running
+      debug:
         msg: "{{ message_installed }}"
         verbosity: 2
       when: not mngmnt_network_container_status

+ 85 - 0
control_plane/roles/control_plane_device/tasks/mapping_file.yml

@@ -0,0 +1,85 @@
+# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+# 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.
+# limitations under the License.
+---
+
+- name: Remove blank lines
+  shell:  set -o pipefail && awk -F, 'length>NF+1' {{ mngmnt_mapping_file_path }} > {{ temp_mgmt_mapping_file }}
+  changed_when: false
+  tags: install
+
+- name: Remove blank spaces
+  shell:  set -o pipefail && sed -i.bak -E 's/(^|,)[[:blank:]]+/\1/g; s/[[:blank:]]+(,|$)/\1/g'  {{ temp_mgmt_mapping_file }}
+  args:
+    warn: no
+  changed_when: false
+  tags: install
+
+- name: Compare the file for new nodes
+  block:
+    - name: Check difference
+      shell: set -o pipefail && diff {{ temp_mgmt_mapping_file }} {{ role_path }}/files/backup_mngmnt_mapping_file.csv| tr -d \>|tr -d \<| grep -E -- ', & :| '
+      register: diff_mngmnt_output
+      changed_when: false
+      failed_when: false
+
+    - name: Status of new nodes
+      set_fact:
+        new_mngmnt_node_status: true
+      when: diff_mngmnt_output.stdout
+  rescue:
+    - name: No new nodes
+      debug:
+        msg: "No new nodes to add"
+        verbosity: 2
+  when: backup_mngmnt_map_status
+
+- name: Fetch inputs from mapping file
+  command: awk 'NR > 1 { print }' {{ temp_mgmt_mapping_file }}
+  changed_when: false
+  register: fetch_mgmt_mapping_file
+
+- name: Fetch input
+  blockinfile:
+    path: "{{ role_path }}/files/dhcpd.conf"
+    insertafter: '^#insert the static DHCP leases for configuration here'
+    block: |
+      host {{ item.split(',')[1] }} {
+        hardware ethernet {{ item.split(',')[0] }};
+        fixed-address {{ item.split(',')[1] }};
+      }
+    marker: "# {mark} DHCP BLOCK OF {{ item.split(',')[0] }}"
+  when: (not mngmnt_network_container_image_status) or (new_mngmnt_node_status)
+  failed_when: false
+  with_items: "{{ fetch_mgmt_mapping_file.stdout_lines }}"
+  tags: install
+
+- name: Create a backup file
+  copy:
+    src: "{{ temp_mgmt_mapping_file }}"
+    dest: "{{ role_path }}/files/backup_mngmnt_mapping_file.csv"
+
+- name: Get mngmnt container pod name
+  command: 'kubectl get pod -n network-config -l app=mngmnt-network -o jsonpath="{.items[0].metadata.name}"'
+  changed_when: false
+  register: mngmnt_pod_name
+  when:  mngmnt_network_container_status
+  tags: install
+
+- name: Copy the dhcp.template inside container
+  command: 'kubectl exec --stdin --tty -n network-config {{ mngmnt_pod_name.stdout }} \
+    -- cp /root/omnia/control_plane/roles/control_plane_device/files/dhcp.template /etc/dhcpd/dhcpd.conf'
+  when:  (  mngmnt_network_container_status ) and ( new_mngmnt_node_status  )
+
+- name: Restart dhcpd
+  command: 'kubectl exec --stdin --tty -n network-config {{ mngmnt_pod_name.stdout }} -- systemctl restart dhcpd'
+  when:  (  mngmnt_network_container_status ) and ( new_mngmnt_node_status )

+ 1 - 0
control_plane/roles/control_plane_device/tasks/mngmnt_network_container_image.yml

@@ -16,6 +16,7 @@
 - name: Image creation (It may take 5-10 mins)
   command: "buildah bud -t {{ mngmnt_network_image_name }}:{{ mngmnt_network_image_tag }} --network host ."
   changed_when: true
+  when: not mngmnt_network_container_image_status
   args:
     chdir: "{{ role_path }}/files/"
   tags: install

+ 6 - 1
control_plane/roles/control_plane_device/vars/main.yml

@@ -15,10 +15,15 @@
 
 # vars file for mngmnt_network
 
+# Usage: main.yml
+base_mngmnt_file: "{{ role_path }}/../../input_params/base_vars.yml"
+
 # Usage: check_prerequisites.yml, mngmnt_network_container_image.yml
 mngmnt_network_image_name: mngmnt_network_container
 mngmnt_network_image_tag: latest
 mount_path: /root/omnia
 message_skipped: "The container is already present"
 message_installed: "The container is installed"
-mngmnt_base_file: "{{ role_path }}/../../input_params/base_vars.yml"
+
+# Usage: mapping_file.yml
+temp_mgmt_mapping_file: "{{ role_path }}/files/new_mngmnt_mapping_file.csv"