main.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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: "{{ mapping_file_exists }}"
  46. no_log: True
  47. - name: Encrypt input config file
  48. command: >-
  49. ansible-vault encrypt {{ input_config_filename }}
  50. --vault-password-file {{ vault_filename }}
  51. changed_when: false
  52. - name: Check if inventory file already exists
  53. stat:
  54. path: "/root/inventory"
  55. register: stat_result
  56. - name: Create inventory file if doesnt exist
  57. copy:
  58. dest: "/root/inventory"
  59. content: |
  60. ---
  61. all:
  62. hosts:
  63. owner: root
  64. mode: 0775
  65. when: not stat_result.stat.exists
  66. - name: Add inventory playbook
  67. block:
  68. - name: add hosts with description to inventory file
  69. command: >-
  70. ansible-playbook -i {{ role_path }}/files/provisioned_hosts.yml
  71. {{ role_path }}/files/create_inventory.yml
  72. --extra-vars "cobbler_username={{ cobbler_username }} cobbler_password={{ cobbler_password }} mapping_file={{ mapping_file | bool }}"
  73. no_log: True
  74. register: register_error
  75. rescue:
  76. - name: Fail if host addition was not successful
  77. fail:
  78. msg: "{{ register_error.stderr + register_error.stdout | regex_replace(cobbler_username) | regex_replace(cobbler_password) }}"
  79. when: provisioned_file_result.stat.exists
  80. - name: push inventory to AWX
  81. command: awx-manage inventory_import --inventory-name {{ omnia_inventory_name }} --source /root/inventory
  82. when: provisioned_file_result.stat.exists