main.yml 3.1 KB

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