Browse Source

Issue #206: Added checks for single-node

Signed-off-by: Blesson James <blesson_james@Dellteam.com>
Lucas A. Wilson 4 years ago
parent
commit
0994304ffe

+ 1 - 1
appliance/roles/common/tasks/password_config.yml

@@ -17,7 +17,7 @@
   command: cat {{ input_config_filename }}
   changed_when: false
   register: config_content
-S
+
 - name: Decrpyt appliance_config.yml
   command: >-
     ansible-vault decrypt {{ input_config_filename }}

+ 6 - 2
appliance/roles/inventory/files/add_host.yml

@@ -35,9 +35,13 @@
   lineinfile:
     path:  "/root/inventory"
     line: "    {{ item }}:\n      _awx_description: {{ host_description }}"
-  when: not check_host.stdout | regex_search(item)
+  when:
+    - not check_host.stdout | regex_search(item)
+    - host_description != "Description Unavailable"
 
 - name: Host added msg
   debug:
     msg: "{{ host_added_msg + item }}"
-  when: not check_host.stdout | regex_search(item)
+  when:
+    - not check_host.stdout | regex_search(item)
+    - host_description != "Description Unavailable"

+ 25 - 11
appliance/roles/inventory/files/create_inventory.yml

@@ -47,45 +47,57 @@
 - name: Set hostname on reachable nodes and gather facts
   hosts: reachable
   gather_facts: False
+  ignore_unreachable: true
   remote_user: "{{ cobbler_username }}"
   vars:
     ansible_password: "{{ cobbler_password }}"
     ansible_become_pass: "{{ cobbler_password }}"
     ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
+    mapping_file_present: ""
   tasks:
     - name: Setup
       setup:
        filter: ansible_*
-    
+
     - name: Check hostname of server
       command: hostname
       register: hostname_check
-      changed_when: false     
+      changed_when: false
+      ignore_errors: true
 
     - name: Check if IP present in mapping file
-      shell: grep "{{ inventory_hostname }}" {{ role_path }}/files/new_mapping_file.csv
+      command: grep "{{ inventory_hostname }}" ../../provision/files/new_mapping_file.csv
       delegate_to: localhost
       register: file_present
-      changed_when: false
+      when: mapping_file == "true"
+      ignore_errors: true
+
+    - name: Set fact if mapping file present
+      set_fact:
+        mapping_file_present: file_present.stdout
+      when: mapping_file == "true"
+      ignore_errors: true
 
     - name: Get the static hostname from mapping file
-      shell:  grep -Po ".* (?="{{ inventory_hostname }}")" {{ role_path }}/files/new_mapping_file.csv| awk -F',' '{print $2}'
+      shell: awk -F',' '$3 == "{{ inventory_hostname }}" { print $2 }' ../../provision/files/new_mapping_file.csv
       delegate_to: localhost
-      when: ('localhost' in hostname_check.stdout) and (file_present.stdout != "")
-      changed_when: false
+      when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and ( mapping_file == "true" )
       register: host_name
+      ignore_errors: true
 
     - name: Set the hostname from mapping file
       hostname:
         name: "{{ host_name.stdout }}"
       register: result_host_name
-      when: ('localhost' in hostname_check.stdout) and (file_present.stdout != "")
+      when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and  (mapping_file == "true" )
+      ignore_errors: true
 
     - name: Set the system hostname
       hostname:
         name: "compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}"
       register: result_name
-      when: ('localhost' in hostname_check.stdout) and (file_present.stdout == "")
+      when: ('localhost' in hostname_check.stdout) and (mapping_file_present == "")
+      ignore_errors: true
 
     - name: Add new hostname to /etc/hosts
       lineinfile:
@@ -93,7 +105,8 @@
         regexp: '^127\.0\.0\.1[ \t]+localhost'
         line: "127.0.0.1 localhost {{ host_name.stdout }}"
         state: present
-      when: "'localhost' in hostname_check.stdout" and (file_present.stdout != "")
+      when: ('localhost' in hostname_check.stdout) and ( mapping_file_present != "" ) and ( mapping_file == "true" )
+      ignore_errors: true
 
     - name: Add new hostname to /etc/hosts
       lineinfile:
@@ -101,7 +114,8 @@
         regexp: '^127\.0\.0\.1[ \t]+localhost'
         line: "127.0.0.1 localhost 'compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}'"
         state: present
-      when: "'localhost' in hostname_check.stdout" and (file_present.stdout == "" )
+      when: ('localhost' in hostname_check.stdout) and (mapping_file_present == "" )
+      ignore_errors: true
 
 - name: Update inventory
   hosts: localhost

+ 4 - 3
appliance/roles/inventory/tasks/main.yml

@@ -49,6 +49,7 @@
     - name: Save input variables from file
       set_fact:
         cobbler_password: "{{ provision_password }}"
+        mapping_file: "{{ mapping_file_exists }}"
       no_log: True
 
     - name: Encrypt input config file
@@ -79,16 +80,16 @@
           command: >-
             ansible-playbook -i {{ role_path }}/files/provisioned_hosts.yml
             {{ role_path }}/files/create_inventory.yml
-            --extra-vars "cobbler_username={{ cobbler_username }} cobbler_password={{ cobbler_password }}"
+            --extra-vars "cobbler_username={{ cobbler_username }} cobbler_password={{ cobbler_password }} mapping_file={{ mapping_file }}"
           no_log: True
           register: register_error
       rescue:
         - name: Fail if host addition was not successful
           fail:
-            msg: "{{ register_error.stdout | regex_replace(cobbler_username) | regex_replace(cobbler_password) }}"
+            msg: "{{ register_error.stderr + register_error.stdout | regex_replace(cobbler_username) | regex_replace(cobbler_password) }}"
 
   when: provisioned_file_result.stat.exists
 
 - name: push inventory to AWX
   command: awx-manage inventory_import --inventory-name {{ omnia_inventory_name }} --source /root/inventory
-  when: provisioned_file_result.stat.exists
+  when: provisioned_file_result.stat.exists

+ 1 - 1
appliance/roles/provision/tasks/provision_password.yml

@@ -34,7 +34,7 @@
   tags: install
 
 - name: Copy cobbler password to cobbler config file
-  shell: printf "%s:%s:%s\n" "{{ username }}" "Cobbler" "{{ encrypt_SSS.stdout }}" > "{{ role_path }}/files/.users.digest"
+  shell: printf "%s:%s:%s\n" "{{ username }}" "Cobbler" "{{ encrypt_password.stdout }}" > "{{ role_path }}/files/.users.digest"
   changed_when: false
   no_log: true
   tags: install

+ 2 - 2
roles/k8s_firewalld/tasks/main.yml

@@ -41,7 +41,7 @@
     permanent: yes
     state: enabled
   with_items: '{{ k8s_compute_ports }}'
-  when: "'compute' in group_names"
+  when: "'compute' in group_names and groups['manager'][0] != groups['compute'][0] and groups['compute']|length >= 1"
   tags: firewalld
 
 - name: Open flannel ports on the firewall
@@ -81,4 +81,4 @@
     name: firewalld
     state: stopped
     enabled: no
-  tags: firewalld
+  tags: firewalld

+ 5 - 3
roles/k8s_nfs_client_setup/tasks/main.yml

@@ -17,6 +17,7 @@
   package:
     name: nfs-utils
     state: present
+  when: groups['manager'][0] != groups['compute'][0] and groups['compute']|length >= 1
   tags: nfs_client
 
 - name: Check mounted share
@@ -33,6 +34,7 @@
     path: "{{ nfs_mnt_dir }}"
     state: directory
     mode: "{{ nfs_mnt_dir_mode }}"
+  when: groups['manager'][0] != groups['compute'][0] and groups['compute']|length >= 1
   tags: nfs_client
 
 - name: Mounting NFS Share
@@ -40,12 +42,12 @@
   changed_when: true
   args:
     warn: false
-  when: groups['manager'][0] not in mounted_share.stdout
+  when: groups['manager'][0] not in mounted_share.stdout and groups['manager'][0] != groups['compute'][0] and groups['compute']|length >= 1
   tags: nfs_client
 
 - name: Configuring Automount NFS Shares on reboot
   lineinfile:
     path: "{{ fstab_file_path }}"
     line: "{{ mounthost }}:{{ nfs_share_dir }}     {{ nfs_mnt_dir }}  nfs     nosuid,rw,sync,hard,intr 0 0"
-  when: groups['manager'][0] not in mounted_share.stdout
-  tags: nfs_client
+  when: groups['manager'][0] not in mounted_share.stdout and groups['manager'][0] != groups['compute'][0] and groups['compute']|length >= 1
+  tags: nfs_client

+ 2 - 1
roles/k8s_nfs_client_setup/vars/main.yml

@@ -14,10 +14,11 @@
 ---
 
 nfs_mnt_dir: /home/k8snfs
+
 nfs_share_dir: /home/k8snfs
 
 mounthost: "{{ groups['manager'][0] }}"
 
 nfs_mnt_dir_mode: 0755
 
-fstab_file_path: /etc/fstab
+fstab_file_path: /etc/fstab