main.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ---
  2. # Variables affecting this role:
  3. #
  4. # tools:
  5. # - final_name: the path to the tool to check for
  6. # completion: generate bash_completion or no
  7. # completion_file: the name of the bash completion file
  8. # download: if no, just skip it
  9. # download_filename: the name of the remote file to download
  10. # archive_filename: the name of the file inside the archive to extract
  11. #
  12. # NOTE: Tools are downloaded from:
  13. # - mirror.openshift.com for a specific ocp_z version, if only download_filename is set
  14. # - arbitrary location, download_url + download_filename if both are set
  15. #
  16. - name: Make sure Downloads exists
  17. file:
  18. path: "{{ ansible_facts['user_dir'] }}/Downloads"
  19. state: directory
  20. owner: student
  21. group: student
  22. mode: 0775
  23. - name: Check whether the tool archive is there
  24. stat:
  25. path: "{{ ansible_facts['user_dir'] }}/Downloads/{{ tools[item].download_filename }}"
  26. when: tools[item].download_filename is defined
  27. register: tool_exists
  28. loop: "{{ tools.keys() | list }}"
  29. - name: Download the (OpenShift) tool if necessary
  30. get_url:
  31. dest: "{{ ansible_facts['user_dir'] }}/Downloads/{{ tools[item].download_filename }}"
  32. url: "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/{{ ocp_z }}/{{ tools[item].download_filename }}"
  33. when:
  34. - tools[item].download_url is not defined
  35. - tools[item].download_filename is defined
  36. - not tool_exists.results[offset].stat.exists
  37. register: tool_downloaded
  38. loop: "{{ tools.keys() | list }}"
  39. loop_control:
  40. index_var: offset
  41. - name: Extract the (OpenShift) tool if downloaded
  42. become: yes
  43. unarchive:
  44. src: "{{ ansible_facts['user_dir'] }}/Downloads/{{ tools[item].download_filename }}"
  45. remote_src: yes
  46. include: "{{ tools[item].archive_filename }}"
  47. dest: "{{ tools[item].final_name | dirname }}"
  48. owner: root
  49. group: root
  50. mode: 0755
  51. when:
  52. - tools[item].download_filename is defined
  53. - tools[item].archive_filename is defined
  54. - tools[item].final_name is defined
  55. - tool_downloaded.results[offset].changed
  56. register: tool_extracted
  57. loop: "{{ tools.keys() | list }}"
  58. loop_control:
  59. index_var: offset
  60. - name: Download the (arbitrary) tool if necessary
  61. get_url:
  62. dest: "{{ ansible_facts['user_dir'] }}/Downloads/{{ tools[item].download_filename }}"
  63. url: "{{ tools[item].download_url }}/{{ tools[item].download_filename }}"
  64. when:
  65. - tools[item].download_url is defined
  66. - tools[item].download_filename is defined
  67. - not tool_exists.results[offset].stat.exists
  68. register: tool_downloaded
  69. loop: "{{ tools.keys() | list }}"
  70. loop_control:
  71. index_var: offset
  72. - name: Extract the (arbitrary) tool if downloaded
  73. become: yes
  74. unarchive:
  75. src: "{{ ansible_facts['user_dir'] }}/Downloads/{{ tools[item].download_filename }}"
  76. remote_src: yes
  77. include: "{{ tools[item].archive_filename }}"
  78. dest: "{{ tools[item].final_name | dirname }}"
  79. owner: root
  80. group: root
  81. mode: 0755
  82. when:
  83. - tools[item].download_filename is defined
  84. - tools[item].archive_filename is defined
  85. - tools[item].final_name is defined
  86. - tool_downloaded.results[offset].changed
  87. register: tool_extracted
  88. loop: "{{ tools.keys() | list }}"
  89. loop_control:
  90. index_var: offset
  91. - name: Generate completion if necessary
  92. become: yes
  93. shell:
  94. cmd: "{{ tools[item].final_name }} completion bash > /etc/bash_completion.d/{{ tools[item].completion_file }}"
  95. when:
  96. - tools[item].completion
  97. - tools[item].completion_file is defined
  98. - tools[item].final_name is defined
  99. - tool_extracted.results[offset].changed
  100. loop: "{{ tools.keys() | list }}"
  101. loop_control:
  102. index_var: offset
  103. ...