main.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright 2020 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: Set Facts
  16. set_fact:
  17. ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
  18. - name: Check if provisioned host file exists
  19. stat:
  20. path: "{{ role_path }}/files/provisioned_hosts.yml"
  21. register: provisioned_file_result
  22. - name: Include vars file of common role
  23. include_vars: "{{ role_path }}/../common/vars/main.yml"
  24. no_log: True
  25. - name: Include vars file of web_ui role
  26. include_vars: "{{ role_path }}/../web_ui/vars/main.yml"
  27. no_log: True
  28. - name: Update inventory file
  29. block:
  30. - name: Check if input config file is encrypted
  31. command: cat {{ input_config_filename }}
  32. changed_when: false
  33. register: config_content
  34. - name: Decrpyt appliance_config.yml
  35. command: >-
  36. ansible-vault decrypt {{ input_config_filename }}
  37. --vault-password-file {{ vault_filename }}
  38. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  39. - name: Include variable file appliance_config.yml
  40. include_vars: "{{ input_config_filename }}"
  41. no_log: True
  42. - name: Save input variables from file
  43. set_fact:
  44. cobbler_password: "{{ provision_password }}"
  45. mapping_file: false
  46. path_mapping_file: "{{ mapping_file_path }}"
  47. no_log: True
  48. - name: Check the status for mapping file
  49. set_fact:
  50. mapping_file: true
  51. when: path_mapping_file != ""
  52. - name: Encrypt input config file
  53. command: >-
  54. ansible-vault encrypt {{ input_config_filename }}
  55. --vault-password-file {{ vault_filename }}
  56. changed_when: false
  57. - name: Check if inventory file already exists
  58. file:
  59. path: "/root/inventory"
  60. state: absent
  61. - name: Create empty inventory file
  62. copy:
  63. dest: "/root/inventory"
  64. content: |
  65. ---
  66. all:
  67. hosts:
  68. owner: root
  69. mode: 0775
  70. - name: Add inventory playbook
  71. block:
  72. - name: add hosts with description to inventory file
  73. command: >-
  74. ansible-playbook -i {{ role_path }}/files/provisioned_hosts.yml
  75. {{ role_path }}/files/create_inventory.yml
  76. --extra-vars "cobbler_username={{ cobbler_username }} cobbler_password={{ cobbler_password }} mapping_file={{ mapping_file | bool }}"
  77. no_log: True
  78. register: register_error
  79. rescue:
  80. - name: Fail if host addition was not successful
  81. fail:
  82. msg: "{{ register_error.stderr + register_error.stdout | regex_replace(cobbler_username) | regex_replace(cobbler_password) }}"
  83. when: provisioned_file_result.stat.exists
  84. - name: push inventory to AWX
  85. command: awx-manage inventory_import --inventory-name {{ omnia_inventory_name }} --source /root/inventory
  86. when: provisioned_file_result.stat.exists