Browse Source

Issue #749: Code changes done for multiprofile support on cobbler

Signed-off-by: Bhagyashree-shetty <Bhagyashree_Shetty@dellteam.com>
Bhagyashree-shetty 3 years ago
parent
commit
17785a0cd2
22 changed files with 346 additions and 112 deletions
  1. 4 4
      control_plane/input_params/base_vars.yml
  2. 2 0
      control_plane/roles/control_plane_device/files/Dockerfile
  3. 2 0
      control_plane/roles/control_plane_device/files/cron_inv
  4. 9 0
      control_plane/roles/control_plane_device/files/inventory_creation.yml
  5. 17 6
      control_plane/roles/control_plane_device/files/mngmnt_container_configure.yml
  6. 2 1
      control_plane/roles/provision_cobbler/files/Dockerfile_leap
  7. 2 1
      control_plane/roles/provision_cobbler/files/Dockerfile_rocky
  8. 6 18
      control_plane/roles/provision_cobbler/files/cobbler_configurations_leap.yml
  9. 9 9
      control_plane/roles/provision_cobbler/files/cobbler_configurations_rocky.yml
  10. 10 4
      control_plane/roles/provision_cobbler/files/inventory_creation.yml
  11. 1 1
      control_plane/roles/provision_cobbler/files/k8s_cobbler.yml
  12. 85 0
      control_plane/roles/provision_cobbler/files/multi_cluster_provisioning.yml
  13. 3 2
      control_plane/roles/provision_cobbler/files/tftp.yml
  14. 36 3
      control_plane/roles/provision_cobbler/tasks/check_prerequisites.yml
  15. 3 3
      control_plane/roles/provision_cobbler/tasks/cobbler_image.yml
  16. 23 7
      control_plane/roles/provision_cobbler/tasks/configure_cobbler.yml
  17. 48 41
      control_plane/roles/provision_cobbler/tasks/main.yml
  18. 2 2
      control_plane/roles/provision_cobbler/tasks/mapping_file.yml
  19. 6 6
      control_plane/roles/provision_cobbler/tasks/mount_iso.yml
  20. 65 0
      control_plane/roles/provision_cobbler/tasks/multi_profile_creation.yml
  21. 5 1
      control_plane/roles/provision_cobbler/tasks/provision_password.yml
  22. 6 3
      control_plane/roles/provision_cobbler/vars/main.yml

+ 4 - 4
control_plane/input_params/base_vars.yml

@@ -90,16 +90,16 @@ provision_method: "idrac"
 provision_state: "stateful"
 
 # This is the operating system image that will be used for provisioning compute nodes in the cluster.
-# Accepted values: rocky, centos
+# Accepted values: rocky, centos, leap
 # Default value: "rocky"
 # Required field
 provision_os: "rocky"
 
 # This is the path where the user has to place the iso image that needs to be provisioned in target nodes.
-# The iso file should be Rocky8-Minimal or CentOS7-2009-minimal edition.
+# The iso file should be Rocky8-Minimal or CentOS7-2009-minimal or openSUSE-Leap-15.3-DVD edition.
 # Other iso files are not supported.
 # Required field
-iso_file_path: "/root/Rocky-8.4-x86_64-minimal.iso"
+iso_file_path: "/root/Rocky-8.5-x86_64-minimal.iso"
 
 # This is the timezone that will be set during provisioning of OS
 # Available timezones are provided in control_plane/common/files/timezone.txt
@@ -175,4 +175,4 @@ ib_network_nic: "ib0"
 # The dhcp range for assigning the IPv4 address
 # Example: 172.17.0.1
 ib_network_dhcp_start_range: "172.25.0.100"
-ib_network_dhcp_end_range: "172.25.0.200"
+ib_network_dhcp_end_range: "172.25.0.200"

+ 2 - 0
control_plane/roles/control_plane_device/files/Dockerfile

@@ -8,9 +8,11 @@ RUN apk add openrc
 
 #Creation of directories and files
 RUN mkdir /root/omnia
+RUN mkdir /etc/periodic/5min
 RUN touch /var/lib/dhcp/dhcpd.leases
 
 #Copy Configuration files
 COPY dhcpd.conf  /etc/dhcp/dhcpd.conf
 COPY inventory_creation.yml /root/
 COPY mngmnt_container_configure.yml /root/
+COPY cron_inv /etc/periodic/5min

+ 2 - 0
control_plane/roles/control_plane_device/files/cron_inv

@@ -0,0 +1,2 @@
+#!/bin/sh
+ansible-playbook /root/inventory_creation.yml

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

@@ -43,6 +43,7 @@
 
     - name: Temp result
       shell: cat /root/omnia/control_plane/roles/collect_device_info/files/mgmt_provisioned_hosts.yml |sort|uniq
+      changed_when: false
       register: inventory
 
     - name: Final Inventory
@@ -51,3 +52,11 @@
     - name: New line at end of file
       shell: echo "">> omnia/control_plane/roles/collect_device_info/files/mgmt_provisioned_hosts.yml
       changed_when: false
+
+    - name: Delete files
+      file:
+        path: "{{ item }}"
+        state: absent
+      with_items:
+        - "/root/temp.txt"
+        -  "/root/dynamic_hosts.yml"

+ 17 - 6
control_plane/roles/control_plane_device/files/mngmnt_container_configure.yml

@@ -20,14 +20,25 @@
   tasks:
   - name: Enable DHCP
     command: dhcpd {{ mngmnt_nic }}
-    
+    changed_when: false
+
+  - name: Start cron
+    command: crond
+    changed_when: false
+
+  - name: Add log file for cron jobs
+    command: crond -L /var/log/cron_jobs
+    changed_when: false
+
+  - name: Add cron job for 5 min
+    shell: echo "*/5    *       *       *       *       run-parts /etc/periodic/5min" >> /var/spool/cron/crontabs/root
+    changed_when: false
+
   - name: Install python-netaddr
     package:
       name: py3-netaddr
       state: present
 
-  - name: Add inventory cron job
-    cron:
-      name: Create inventory
-      minute: "*/5"
-      job: /root/inventory_creation.yml"
+  - name: Change permissions
+    command: chmod a+x /etc/periodic/5min/cron_inv
+    changed_when: false

+ 2 - 1
control_plane/roles/provision_cobbler/files/Dockerfile_leap

@@ -59,6 +59,7 @@ COPY .users.digest /etc/cobbler/users.digest
 COPY cobbler_configurations_leap.yml /root
 COPY tftp.yml /root
 COPY inventory_creation.yml /root
+COPY multi_cluster_provisioning.yml /root
 
 EXPOSE 69 80 443 25151
 
@@ -67,4 +68,4 @@ VOLUME [ "/srv/www/cobbler", "/var/lib/cobbler/backup", "/mnt" ]
 RUN systemctl enable apache2
 RUN systemctl enable dhcpd
 
-CMD ["sbin/init"]
+CMD ["sbin/init"]

+ 2 - 1
control_plane/roles/provision_cobbler/files/Dockerfile_rocky

@@ -58,6 +58,7 @@ COPY .users.digest /etc/cobbler/users.digest
 COPY cobbler_configurations_rocky.yml /root
 COPY tftp.yml /root
 COPY inventory_creation.yml /root
+COPY multi_cluster_provisioning.yml /root
 
 EXPOSE 69 80 443 25151
 
@@ -66,4 +67,4 @@ VOLUME [ "/var/www/cobbler", "/var/lib/cobbler/backup", "/mnt" ]
 RUN systemctl enable httpd
 RUN systemctl enable dhcpd
 
-CMD ["sbin/init"]
+CMD ["sbin/init"]

+ 6 - 18
control_plane/roles/provision_cobbler/files/cobbler_configurations_leap.yml

@@ -1,4 +1,4 @@
-#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2022 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.
@@ -77,21 +77,21 @@
     shell: export PATH="/usr/bin/curl:$PATH"
 
   - name: Run import command
-    command: cobbler import --arch=x86_64 --path=/mnt --name="{{ name_iso }}"
+    command: cobbler import --arch=x86_64 --path=/mnt/{{ provision_os }} --name="{{ provision_os }}"
     changed_when: false
 
   - name: Kickstart profile - leap
     copy:
       src: "/root/leap15.xml"
       dest: "/var/lib/cobbler/templates/sample_autoyast.xml"
-      mode: 0775
+      mode: "{{ file_perm }}"
     tags: install
 
   - name: Pxe menu
     copy:
       src: "/root/omnia/control_plane/roles/provision_cobbler/files/menu.yml"
       dest: "/etc/cobbler/boot_loader_conf/pxedefault.template"
-      mode: 0775
+      mode: "{{ file_perm }}"
     tags: install
 
   - name: Assign default grub option
@@ -127,26 +127,14 @@
     changed_when: false
     register: ansible_playbook_path
 
-#  - name: Set dhcpd_lease_file variable for inventory creation
-#    cron:
-#      env: yes
-#      name: dhcpd_lease_file
-#      value: "/var/lib/dhcp/db/dhcpd.leases"
-
-#  - name: Set provision_os variable for inventory creation
-#    cron:
-#      env: yes
-#      name: provision_os
-#      value: "{{ name_iso }}"
-
   - name: Add tftp cron job
     cron:
       name: Start tftp service
       minute: "*"
-      job: "{{ ansible_playbook_path.stdout.split(' ')[1] }} /root/tftp.yml -e provision_os={{ name_iso }}"
+      job: "{{ ansible_playbook_path.stdout.split(' ')[1] }} /root/tftp.yml"
 
   - name: Add inventory cron job
     cron:
       name: Create inventory
       minute: "*/5"
-      job: "{{ ansible_playbook_path.stdout.split(' ')[1] }} /root/inventory_creation.yml -e dhcpd_lease_file=\"/var/lib/dhcp/db/dhcpd.leases\""
+      job: "{{ ansible_playbook_path.stdout.split(' ')[1] }} /root/inventory_creation.yml"

+ 9 - 9
control_plane/roles/provision_cobbler/files/cobbler_configurations_rocky.yml

@@ -68,37 +68,37 @@
     shell: export PATH="/usr/bin/curl:$PATH"
 
   - name: Run import command
-    command: cobbler import --arch=x86_64 --path=/mnt --name="{{ name_iso }}"
+    command: cobbler import --arch=x86_64 --path=/mnt/{{ provision_os }} --name="{{ provision_os }}"
     changed_when: false
 
   - name: Kickstart profile - centos
     copy:
       src: "/root/centos7.ks"
       dest: "/var/lib/cobbler/templates/sample.ks"
-      mode: 0775
+      mode: "{{ file_perm }}"
     tags: install
-    when: name_iso == "centos"
+    when: provision_os == "centos"
 
   - name: Kickstart profile - rocky
     copy:
       src: "/root/rocky8.ks"
       dest: "/var/lib/cobbler/templates/sample.ks"
-      mode: 0775
+      mode: "{{ file_perm }}"
     tags: install
-    when: name_iso == "rocky"
+    when: provision_os == "rocky"
 
   - name: Pxe menu
     copy:
       src: "/root/omnia/control_plane/roles/provision_cobbler/files/menu.yml"
       dest: "/etc/cobbler/boot_loader_conf/pxedefault.template"
-      mode: 0775
+      mode: "{{ file_perm }}"
     tags: install
 
   - name: Assign default grub option
     replace:
       path: "/var/lib/cobbler/grub_config/grub/grub.cfg"
-      regexp: "^set default=\'local\'"
-      replace: "set default=\'1\'"
+      regexp: "^set default='local'"
+      replace: "set default='1'"
     tags: install
 
   - name: Assign default grub timeout
@@ -137,4 +137,4 @@
     cron:
       name: Create inventory
       minute: "*/5"
-      job: "{{ ansible_playbook_path.stdout.split(' ')[1] }} /root/inventory_creation.yml -e dhcpd_lease_file=\"/var/lib/dhcpd/dhcpd.leases\""
+      job: "{{ ansible_playbook_path.stdout.split(' ')[1] }} /root/inventory_creation.yml"

+ 10 - 4
control_plane/roles/provision_cobbler/files/inventory_creation.yml

@@ -1,10 +1,16 @@
 - hosts: localhost
   connection: local
-  gather_facts: false
+  gather_facts: true
   tasks:
-    - name: Read dhcp file
+    - name: Read dhcp file for rocky
       set_fact:
-        var: "{{ lookup('file', '{{ dhcpd_lease_file }}').split()| unique | select| list }}"
+        var: "{{ lookup('file', '/var/lib/dhcpd/dhcpd.leases').split()| unique | select| list }}"
+      when: ansible_facts['distribution'] | lower == "rocky"
+
+    - name: Read dhcp file for leap
+      set_fact:
+        var: "{{ lookup('file', '/var/lib/dhcp/db/dhcpd.leases').split()| unique | select| list }}"
+      when: ansible_facts['distribution'] | lower == "leap"
     
     - name: Filter the ip
       set_fact:
@@ -35,4 +41,4 @@
 
     - name: New line at end of file
       shell: echo "">> omnia/control_plane/roles/collect_node_info/files/provisioned_hosts.yml
-      changed_when: false
+      changed_when: false

+ 1 - 1
control_plane/roles/provision_cobbler/files/k8s_cobbler.yml

@@ -25,7 +25,7 @@ spec:
             type: Directory
         - name: mnt-iso
           hostPath:
-            path: /mnt/iso/
+            path: /mnt/
             type: Directory
       containers:
         - name: cobbler

+ 85 - 0
control_plane/roles/provision_cobbler/files/multi_cluster_provisioning.yml

@@ -0,0 +1,85 @@
+#  Copyright 2022 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: Initial cobbler setup
+  hosts: localhost
+  connection: local
+  gather_facts: false
+  tasks:
+    - name: Initialize variables
+      set_fact:
+        multi_profile: false
+        grub_option: 1
+
+    - name: Run import command
+      command: cobbler import --arch=x86_64 --path=/mnt/{{ provision_os }} --name="{{ provision_os }}"
+      changed_when: false
+
+    - name: Kickstart profile - centos
+      copy:
+        src: "/root/centos7.ks"
+        dest: "/var/lib/cobbler/templates/sample.ks"
+        mode: "{{ file_perm }}"
+      tags: install
+      when: provision_os == "centos"
+
+    - name: Kickstart profile - rocky
+      copy:
+        src: "/root/rocky8.ks"
+        dest: "/var/lib/cobbler/templates/sample.ks"
+        mode: "{{ file_perm }}"
+      tags: install
+      when: provision_os == "rocky"
+
+    - name: Kickstart profile - leap
+      copy:
+        src: "/root/leap15.xml"
+        dest: "/var/lib/cobbler/templates/sample_autoyast.xml"
+        mode: "{{ file_perm }}"
+      tags: install
+      when: provision_os == "leap"
+
+    - name: Get the cobbler profile list
+      command: cobbler profile list
+      changed_when: false
+      register: cobbler_profile_list
+      failed_when: false
+
+    - name: Check if cobbler_profile_list has more that one profile
+      set_fact:
+        multi_profile: true
+      when:
+        - cobbler_profile_list.stdout_lines| length > 1
+
+    - name: Check if the provision os is in cobbler_profile_list
+      set_fact:
+        grub_option: "{{ index + 1 }}"
+      when:
+        - provision_os in item
+        - multi_profile
+      loop: "{{ cobbler_profile_list.stdout_lines | flatten(levels=1) }}"
+      loop_control:
+        index_var: index
+
+    - name: Assign default grub option
+      replace:
+        path: "/var/lib/cobbler/grub_config/grub/grub.cfg"
+        regexp: "^set default=.*"
+        replace: "set default='{{ grub_option }}'"
+      tags: install
+
+    - name: Syncing of cobbler
+      command: cobbler sync
+      changed_when: false

+ 3 - 2
control_plane/roles/provision_cobbler/files/tftp.yml

@@ -1,4 +1,4 @@
-#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2022 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.
@@ -16,6 +16,7 @@
 - name: Start tftp and dhcp
   hosts: localhost
   connection: local
+  gather_facts: true
   tasks:
     - name: Configure tftp for leap
       block:
@@ -36,7 +37,7 @@
 
         - name: Start tftp.socket
           command: systemctl start tftp.socket
-      when: provision_os == "leap"
+      when: ansible_facts['distribution'] | lower == "leap"
 
     - name: Fetch tftp status
       command: systemctl is-active tftp

+ 36 - 3
control_plane/roles/provision_cobbler/tasks/check_prerequisites.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 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.
@@ -20,6 +20,8 @@
     cobbler_config_status: false
     backup_map_status: false
     new_node_status: false
+    provision_os_change: false
+    previous_os: None
   tags: install
 
 - name: Set centos kickstart file name
@@ -111,11 +113,42 @@
   failed_when: false
   when: cobbler_container_status
 
+- name: Check if .provisioned_os file exists
+  stat:
+    path: "/root/omnia/control_plane/roles/provision_cobbler/files/.provisioned_os"
+  register: provisioned_os_file
+
+- name: Create .provisioned_os file
+  file:
+    path: "{{ role_path }}/files/.provisioned_os"
+    state: touch
+  when: not provisioned_os_file.stat.exists
+
+- name: Check status of .provisioned_os file
+  stat:
+    path: "{{ role_path }}/files/.provisioned_os"
+  register: provisioned_os_file
+
+- name: Get the previous os provisioned
+  set_fact:
+    previous_os: "{{ lookup('file', '{{ role_path }}/files/.provisioned_os').split() | last }}"
+  when:
+    - provisioned_os_file.stat.exists
+    - provisioned_os_file.stat.size > 0
+
 - name: Update cobbler config status
   set_fact:
     cobbler_config_status: true
   when:
     - cobbler_container_status
-    - provision_os in cobbler_profile_list.stdout
+    - (provision_os in cobbler_profile_list.stdout) or (previous_os in cobbler_profile_list.stdout)
     - "'* * * * * /usr/bin/ansible-playbook /root/tftp.yml' in crontab_list.stdout"
-    - "'*/5 * * * * /usr/bin/ansible-playbook /root/inventory_creation.yml' in crontab_list.stdout"
+    - "'*/5 * * * * /usr/bin/ansible-playbook /root/inventory_creation.yml' in crontab_list.stdout"
+
+- name: Set status for provison_os_change
+  set_fact:
+    provision_os_change: true
+  when:
+    - previous_os != None
+    - previous_os != provision_os
+    - cobbler_config_status

+ 3 - 3
control_plane/roles/provision_cobbler/tasks/cobbler_image.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 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.
@@ -14,7 +14,7 @@
 ---
 
 - name: Image creation (It may take 5-10 mins)
-  command: "buildah bud  -f Dockerfile_rocky -t {{ cobbler_image_name }}:{{ cobbler_image_tag }} --network host ."
+  command: "buildah bud -f Dockerfile_rocky -t {{ cobbler_image_name }}:{{ cobbler_image_tag }} --network host ."
   changed_when: true
   args:
     chdir: "{{ role_path }}/files/"
@@ -48,4 +48,4 @@
 - name: Deploy cobbler pod
   command: "kubectl apply -f {{ role_path }}/files/k8s_cobbler.yml"
   changed_when: true
-  tags: install
+  tags: install

+ 23 - 7
control_plane/roles/provision_cobbler/tasks/configure_cobbler.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 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.
@@ -17,7 +17,10 @@
   command: "kubectl apply -f {{ role_path }}/files/k8s_cobbler.yml"
   changed_when: true
   tags: install
-  when: cobbler_container_status and not cobbler_config_status
+  when:
+    - cobbler_container_status
+    - not cobbler_config_status
+    - not provision_os_change
 
 - name: Wait for cobbler pod to come to ready state
   command: kubectl wait --for=condition=ready -n {{ cobbler_namespace }} pod -l app=cobbler
@@ -40,20 +43,28 @@
   when: not cobbler_config_status
 
 - name: Configuring cobbler inside container (It may take 5-10 mins)
-  command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- ansible-playbook /root/cobbler_configurations_rocky.yml -e name_iso={{ provision_os }}"
+  command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- ansible-playbook /root/cobbler_configurations_rocky.yml -e provision_os={{ provision_os }} -e file_perm={{ file_perm }}"
   changed_when: true
   tags: install
-  when: 
+  when:
     - not cobbler_config_status
     - mgmt_os == os_supported_rocky
-      
+    - not provision_os_change
+
 - name: Configuring cobbler inside container (It may take 5-10 mins)
-  command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- ansible-playbook /root/cobbler_configurations_leap.yml -e name_iso={{ provision_os }} -e host_network_nic={{ host_network_nic }}"
+  command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- ansible-playbook /root/cobbler_configurations_leap.yml -e provision_os={{ provision_os }} -e host_network_nic={{ host_network_nic }}  -e file_perm={{ file_perm }}"
   changed_when: true
   tags: install
-  when: 
+  when:
     - not cobbler_config_status
     - mgmt_os == os_supported_leap
+    - not provision_os_change
+
+- name: Configuring cobbler for multiple profile support
+  command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- ansible-playbook /root/multi_cluster_provisioning.yml -e provision_os={{ provision_os }} -e provision_os_change={{ provision_os_change }} -e file_perm={{ file_perm }}"
+  changed_when: true
+  tags: install
+  when: provision_os_change
 
 - name: Schedule task
   cron:
@@ -68,6 +79,10 @@
   changed_when: true
   when: cobbler_config_status
 
+- name: Store the provisioned os in .provisioned_os.txt file
+  shell: echo "{{ provision_os }}">> {{ role_path }}/files/.provisioned_os
+  changed_when: false
+
 - name: Remove the files
   file:
     path: "{{ item }}"
@@ -78,3 +93,4 @@
     - "{{ role_path }}/files/settings"
     - "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
     - "{{ role_path }}/files/temp_host_mapping_file.csv.bak"
+    - "/mnt/tmp"

+ 48 - 41
control_plane/roles/provision_cobbler/tasks/main.yml

@@ -1,4 +1,4 @@
-#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2022 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.
@@ -18,52 +18,59 @@
 - name: Check cobbler status on machine
   include_tasks: check_prerequisites.yml
 
-- name: Mount iso image
-  import_tasks: mount_iso.yml
-  when: not cobbler_image_status
+- name: Multi profile creation
+  import_tasks: multi_profile_creation.yml
+  when: provision_os_change
 
-- name: Modify firewall settings for Cobbler
-  import_tasks: firewall_settings.yml
-  when: not cobbler_container_status
-
-- name: Include common variables
-  include_vars: ../../control_plane_common/vars/main.yml
-  when: not cobbler_container_status
+- name: Cobbler pod creation
+  block:
+    - name: Mount iso image
+      import_tasks: mount_iso.yml
+      when: not cobbler_image_status
 
-- name: Internet validation
-  include_tasks: ../../control_plane_common/tasks/internet_validation.yml
-  when: not cobbler_container_status
+    - name: Modify firewall settings for Cobbler
+      import_tasks: firewall_settings.yml
+      when: not cobbler_container_status
 
-- name: Dhcp Configuration
-  import_tasks: dhcp_configure.yml
-  when: (not cobbler_image_status) or ( backup_map_status )
+    - name: Include common variables
+      include_vars: ../../control_plane_common/vars/main.yml
+      when: not cobbler_container_status
 
-- name: Provision password validation
-  import_tasks: provision_password.yml
-  when: not cobbler_image_status
+    - name: Internet validation
+      include_tasks: ../../control_plane_common/tasks/internet_validation.yml
+      when: not cobbler_container_status
 
-- name: Mapping file validation
-  import_tasks: mapping_file.yml
-  when: (not cobbler_image_status) and (host_mapping_file) or ( backup_map_status)
+    - name: Dhcp Configuration
+      import_tasks: dhcp_configure.yml
+      when: (not cobbler_image_status) or ( backup_map_status )
 
-- name: Cobbler image creation
-  import_tasks: cobbler_image.yml
-  when: not cobbler_container_status
+    - name: Provision password validation
+      import_tasks: provision_password.yml
+      when: not cobbler_image_status
 
-- name: Cobbler configuration
-  import_tasks: configure_cobbler.yml
-  when: not cobbler_config_status
+    - name: Mapping file validation
+      import_tasks: mapping_file.yml
+      when: (not cobbler_image_status) and (host_mapping_file) or ( backup_map_status)
 
-- name: Cobbler container status message
-  block:
-    - name: cobbler container running
-      debug:
-        msg: "{{ message_skipped }}"
-        verbosity: 2
-      when: cobbler_container_status
-    - name: cobbler container not running
-      debug:
-        msg: "{{ message_installed }}"
-        verbosity: 2
+    - name: Cobbler image creation
+      import_tasks: cobbler_image.yml
       when: not cobbler_container_status
-  tags: install
+
+    - name: Cobbler configuration
+      import_tasks: configure_cobbler.yml
+      when: not cobbler_config_status
+
+    - name: Cobbler container status message
+      block:
+        - name: cobbler container running
+          debug:
+            msg: "{{ message_skipped }}"
+            verbosity: 2
+          when: cobbler_container_status
+        - name: cobbler container not running
+          debug:
+            msg: "{{ message_installed }}"
+            verbosity: 2
+          when: not cobbler_container_status
+      tags: install
+  when: not provision_os_change

+ 2 - 2
control_plane/roles/provision_cobbler/tasks/mapping_file.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 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.
@@ -68,7 +68,7 @@
   copy:
     src: "{{ temp_host_mapping_file }}"
     dest: "{{ role_path }}/files/backup_host_mapping_file.csv"
-    mode: 0644
+    mode: "{{ temp_file_perm }}"
 
 - name: Get cobbler pod name
   command: 'kubectl get pod -n {{ cobbler_namespace }} -l app=cobbler -o jsonpath="{.items[0].metadata.name}"'

+ 6 - 6
control_plane/roles/provision_cobbler/tasks/mount_iso.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 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.
@@ -20,19 +20,19 @@
 
 - name: Check iso directory status
   stat:
-    path: "/mnt/{{ iso_dir_name }}"
+    path: "/mnt/{{ provision_os }}"
   register: check_iso_dir
 
 - name: Create iso directory
   file:
-    path: "/mnt/{{ iso_dir_name }}"
+    path: "/mnt/{{ provision_os }}"
     state: directory
-    mode: 0644
+    mode: "{{ temp_file_perm }}"
   tags: install
   when: not check_iso_dir.stat.exists
 
 - name: Check mountpoint
-  command: mountpoint /mnt/{{ iso_dir_name }}
+  command: mountpoint /mnt/
   changed_when: false
   register: result
   failed_when: false
@@ -44,7 +44,7 @@
   tags: install
 
 - name: Mount the iso file
-  command: mount -o loop {{ iso_file_path }} /mnt/{{ iso_dir_name }}
+  command: mount -o loop {{ iso_file_path }} /mnt/{{ provision_os }}
   changed_when: false
   args:
     warn: no

+ 65 - 0
control_plane/roles/provision_cobbler/tasks/multi_profile_creation.yml

@@ -0,0 +1,65 @@
+# Copyright 2022 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: Validate cobbler configuration status
+  set_fact:
+    cobbler_config_status: false
+    profile_exists: false
+  when: cobbler_config_status
+
+- name: Check prifile for {{ provision_os }} exists
+  set_fact:
+    profile_exists: true
+  when: provision_os in cobbler_profile_list.stdout
+
+- name: Create a temp iso directory to mount the iso files
+  file:
+    path: "/mnt/tmp"
+    state: directory
+    mode: "{{ temp_file_perm }}"
+  when: not profile_exists
+
+- name: Check {{ provision_os }} folder status
+  stat:
+    path: "/mnt/{{ provision_os }}"
+  register: file_status
+
+- name: Create directory for {{ provision_os }} to copy the iso files
+  file:
+    path: "/mnt/{{ provision_os }}"
+    state: directory
+    mode: "{{ temp_file_perm }}"
+  when:
+    - not file_status.stat.exists
+    - not profile_exists
+
+- name: Mount the iso file
+  command: mount -o loop {{ iso_file_path }} /mnt/tmp
+  when: not profile_exists
+
+- name: Copy the iso file inside /mnt
+  command: cp -rf /mnt/tmp/. /mnt/{{ provision_os }}
+  changed_when: false
+  when: not profile_exists
+
+- name: Unmount /mnt/tmp for further mounts
+  command: umount /mnt/tmp
+  when: not profile_exists
+
+- name: Provision password validation
+  import_tasks: provision_password.yml
+
+- name: Cobbler configuration
+  import_tasks: configure_cobbler.yml

+ 5 - 1
control_plane/roles/provision_cobbler/tasks/provision_password.yml

@@ -1,4 +1,4 @@
-#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2022 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.
@@ -18,6 +18,7 @@
     path: "{{ role_path }}/files/.users.digest"
     state: absent
   tags: install
+  when: not provision_os_change
 
 - name: Create a new user
   file:
@@ -25,18 +26,21 @@
     state: touch
     mode: "{{ user_mode }}"
   tags: install
+  when: not provision_os_change
 
 - name: Cobbler UI password
   set_fact:
         encrypt_password: "{{ cobbler_password | hash('sha3_256') }}"
   no_log: true
   tags: install
+  when: not provision_os_change
 
 - name: Copy cobbler password to cobbler config file
   shell: printf "%s:%s:%s\n" "{{ username }}" "Cobbler" "{{ encrypt_password }}" > "{{ role_path }}/files/.users.digest"
   changed_when: false
   no_log: true
   tags: install
+  when: not provision_os_change
 
 - name: Kickstart configuration - centos
   block:

+ 6 - 3
control_plane/roles/provision_cobbler/vars/main.yml

@@ -1,4 +1,4 @@
-# Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+# Copyright 2022 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.
@@ -66,5 +66,8 @@ cobbler_image_tag: latest
 message_skipped: "Installation Skipped: Cobbler instance is already running in your system"
 message_installed: "Installation Successful"
 
-# Usage: mount_iso.yml
-iso_dir_name: iso
+# Usage: multi_cluster_provisioning.yml
+file_perm: '0775'
+
+# Usage: multi_cluster_provisioning.yml
+temp_file_perm: '0644'