fetch_powervault_status.yml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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: Check tower_cli.cfg is encrypted
  16. command: cat "{{ tower_config_path }}"
  17. changed_when: false
  18. register: awx_content
  19. run_once: true
  20. no_log: true
  21. - name: Decrpyt tower_cli.cfg
  22. command: ansible-vault decrypt "{{ tower_config_path }}" --vault-password-file "{{ tower_vault_path }}"
  23. changed_when: false
  24. run_once: true
  25. when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
  26. - name: Fetch awx host
  27. command: grep "host:" "{{ tower_config_path }}"
  28. register: fetch_awx_host
  29. changed_when: false
  30. run_once: true
  31. - name: Fetch awx username
  32. command: grep "username:" "{{ tower_config_path }}"
  33. register: fetch_awx_username
  34. changed_when: false
  35. run_once: true
  36. no_log: true
  37. - name: Fetch awx password
  38. command: grep "password:" "{{ tower_config_path }}"
  39. register: fetch_awx_password
  40. changed_when: false
  41. run_once: true
  42. no_log: true
  43. - name: Set awx variables
  44. set_fact:
  45. awx_host: "{{ fetch_awx_host.stdout | regex_replace('host: ','') }}"
  46. awx_username: "{{ fetch_awx_username.stdout | regex_replace('username: ','') }}"
  47. awx_password: "{{ fetch_awx_password.stdout | regex_replace('password: ','') }}"
  48. no_log: true
  49. - name: Encrypt tower_cli.cfg
  50. command: ansible-vault encrypt "{{ tower_config_path }}" --vault-password-file "{{ tower_vault_path }}"
  51. changed_when: false
  52. run_once: true
  53. when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
  54. - name: Get inventory list
  55. command: >-
  56. awx --conf.host "{{ awx_host }}" --conf.username "{{ awx_username }}" --conf.password "{{ awx_password }}"
  57. inventory list -f human --filter "name"
  58. register: inventory_list
  59. run_once: true
  60. changed_when: false
  61. no_log: true
  62. - block:
  63. - name: Fetch powervault_me4_inventory
  64. command: >-
  65. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  66. hosts list --inventory "{{ powervault_inventory_name }}" -f human --filter "name"
  67. register: fetch_inventory
  68. run_once: true
  69. changed_when: false
  70. no_log: true
  71. - name: Set powervault_status
  72. set_fact:
  73. powervault_status: true
  74. when: fetch_inventory.stdout_lines[2:] | length > 0
  75. - name: Create powervault_me4 group
  76. add_host:
  77. name: "{{ item | regex_replace(' ','') }}"
  78. groups: "{{ powervault_group }}"
  79. when: powervault_status
  80. with_items: "{{ fetch_inventory.stdout_lines[2:] }}"