main.yml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Copyright 2022 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: Fetch the execution environment
  19. command: hostname
  20. register: host_name
  21. changed_when: false
  22. - name: Install sshpass
  23. package:
  24. name: sshpass
  25. state: present
  26. when: awx_search_key not in host_name.stdout
  27. - name: Check if provisioned host file exists
  28. stat:
  29. path: "{{ provisioned_hosts_file }}"
  30. register: provisioned_file
  31. - name: Include variable file base_vars.yml
  32. include_vars: "{{ base_vars_file }}"
  33. - name: Update inventory
  34. block:
  35. - name: Check if {{ login_vars_file }} file is encrypted
  36. command: cat {{ login_vars_file }}
  37. changed_when: false
  38. no_log: true
  39. register: config_content
  40. run_once: true
  41. - name: Decrpyt {{ login_vars_file }}
  42. command: >-
  43. ansible-vault decrypt {{ login_vars_file }}
  44. --vault-password-file {{ login_vault_file }}
  45. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  46. changed_when: false
  47. run_once: true
  48. - name: Include variable file {{ login_vars_file }}
  49. include_vars: "{{ login_vars_file }}"
  50. no_log: true
  51. run_once: true
  52. - name: Save input variables from file
  53. set_fact:
  54. mapping_file: false
  55. - name: Check the status for mapping file
  56. set_fact:
  57. mapping_file: true
  58. when: host_mapping_file_path
  59. - name: Encrypt {{ login_vars_file }}
  60. command: >-
  61. ansible-vault encrypt {{ login_vars_file }}
  62. --vault-password-file {{ login_vault_file }}
  63. changed_when: false
  64. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  65. run_once: true
  66. - name: Change file permissions
  67. file:
  68. path: "{{ login_vars_file }}"
  69. mode: "{{ file_perm }}"
  70. - name: Check the provisioned_hosts_file output
  71. command: cat {{ provisioned_hosts_file }}
  72. changed_when: false
  73. register: os_hosts
  74. - name: Create device_inventory
  75. add_host:
  76. name: "{{ item }}"
  77. groups: "node_inventory"
  78. with_items: "{{ os_hosts.stdout_lines }}"
  79. when: item | trim | length > 1
  80. when: provisioned_file.stat.exists