validate_ldap_vars.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Include provision_idrac vars
  16. include_vars: "{{ playbook_dir }}/../roles/provision_idrac/vars/main.yml"
  17. run_once: true
  18. - name: Include control_plane_common vars
  19. include_vars: "{{ playbook_dir }}/../roles/control_plane_common/vars/main.yml"
  20. run_once: true
  21. - name: Include idrac_vars.yml
  22. include_vars: "{{ playbook_dir }}/../{{ idrac_input_filename }}"
  23. run_once: true
  24. - name: Set ldap_directory_services in lowercase
  25. set_fact:
  26. ldap_directory_services: "{{ ldap_directory_services | lower }}"
  27. - name: Assert ldap_directory_services value
  28. assert:
  29. that:
  30. - ldap_directory_services | length > 1
  31. - ldap_directory_services == "enabled" or ldap_directory_services == "disabled"
  32. success_msg: "{{ ldap_success_msg }}"
  33. fail_msg: "{{ ldap_fail_msg }}"
  34. - block:
  35. - name: Check idrac_tools_vars.yml file is encrypted
  36. command: cat "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  37. changed_when: false
  38. run_once: true
  39. register: config_content
  40. - name: Decrpyt idrac_tools_vars.yml
  41. command: >-
  42. ansible-vault decrypt "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  43. --vault-password-file "{{ playbook_dir }}/../{{ idrac_tools_vaultname }}"
  44. changed_when: false
  45. run_once: true
  46. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  47. - name: Include variable file idrac_tools_vars.yml
  48. include_vars: "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  49. run_once: true
  50. no_log: true
  51. - name: Validate LDAP parameters are not empty
  52. fail:
  53. msg: "{{ ldap_input_fail_msg }}"
  54. when:
  55. - cert_validation_enable | length < 1 or
  56. ldap_server_address | length < 1 or
  57. ldap_port | length < 1 or
  58. base_dn | length < 1 or
  59. group_attribute_is_dn | length < 1 or
  60. role_group1_dn | length < 1 or
  61. role_group1_privilege | length < 1
  62. - name: Set ldap_directory_services in lowercase
  63. set_fact:
  64. cert_validation_enable: "{{ cert_validation_enable | lower }}"
  65. group_attribute_is_dn: "{{ group_attribute_is_dn | lower }}"
  66. base_dn: "{{ base_dn | lower }}"
  67. role_group1_dn: "{{ role_group1_dn | lower }}"
  68. bind_dn: "{{ bind_dn | lower }}"
  69. - name: Assert cert_validation_enable value
  70. assert:
  71. that: cert_validation_enable == "disabled"
  72. success_msg: "{{ cert_validation_success_msg }}"
  73. fail_msg: "{{ cert_validation_fail_msg }}"
  74. - name: Assert bind_dn value
  75. assert:
  76. that:
  77. - '"dc=" in bind_dn'
  78. - '"ou=" in bind_dn'
  79. success_msg: "{{ bind_dn_success_msg }}"
  80. fail_msg: "{{ bind_dn_fail_msg }}"
  81. when: bind_dn | length > 1
  82. - name: Assert base_dn value
  83. assert:
  84. that: '"dc=" in base_dn'
  85. success_msg: "{{ base_dn_success_msg }}"
  86. fail_msg: "{{ base_dn_fail_msg }}"
  87. - name: Assert group_attribute_is_dn value
  88. assert:
  89. that: group_attribute_is_dn == "disabled" or group_attribute_is_dn == "enabled"
  90. success_msg: "{{ group_attribute_success_msg }}"
  91. fail_msg: "{{ group_attribute_fail_msg }}"
  92. - name: Assert role_group1_dn value
  93. assert:
  94. that:
  95. - '"dc=" in role_group1_dn'
  96. - '"ou=" in role_group1_dn'
  97. success_msg: "{{ role_group1_dn_success_msg }}"
  98. fail_msg: "{{ role_group1_dn_fail_msg }}"
  99. - name: Assert role_group1_privilege value
  100. assert:
  101. that:
  102. - role_group1_privilege == "Administrator" or
  103. role_group1_privilege == "Operator" or
  104. role_group1_privilege == "ReadOnly"
  105. success_msg: "{{ role_group1_privilege_success_msg }}"
  106. fail_msg: "{{ role_group1_privilege_fail_msg }}"
  107. - name: Set role_group1_privilege value
  108. set_fact:
  109. role_group1_privilege_id: "{{ item.value }}"
  110. when: item.name == role_group1_privilege
  111. with_items:
  112. - { name: "Administrator", value: "511" }
  113. - { name: "Operator", value: "499" }
  114. - { name: "ReadOnly", value: "1" }
  115. - name: Encrypt idrac_tools_vars.yml
  116. command: >-
  117. ansible-vault encrypt "{{ playbook_dir }}/../{{ idrac_tools_vars_filename }}"
  118. --vault-password-file "{{ playbook_dir }}/../{{ idrac_tools_vaultname }}"
  119. changed_when: false
  120. run_once: true
  121. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  122. when: ldap_directory_services == "enabled"