main.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ---
  2. - name: gather os specific variables
  3. include_vars: "{{ item }}"
  4. with_first_found:
  5. - files:
  6. - "{{ ansible_distribution | lower | regex_replace('[^a-zA-Z0-9 ]+|[ ]+$', '') |replace(' ','_') | lower}}-{{ansible_distribution_release}}.yml"
  7. - "{{ ansible_distribution | lower | regex_replace('[^a-zA-Z0-9 ]+|[ ]+$', '') |replace(' ','_') | lower}}.yml"
  8. - "{{ ansible_distribution | lower | replace(' ', '_') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.{{ ansible_architecture }}.yml"
  9. - "{{ ansible_distribution | lower | replace(' ', '_') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  10. - "{{ ansible_distribution | lower | replace(' ', '_') }}-{{ ansible_distribution_release|lower }}-{{ ansible_architecture }}.yml"
  11. - "{{ ansible_distribution | lower | replace(' ', '_') }}-{{ ansible_distribution_release|lower }}.yml"
  12. - "{{ ansible_distribution | lower | replace(' ', '_') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  13. - "{{ ansible_distribution | lower | replace(' ', '_') }}-{{ ansible_architecture }}.yml"
  14. - "{{ ansible_distribution | lower | replace(' ', '_') }}.yml"
  15. - "{{ ansible_os_family|lower }}-{{ ansible_architecture }}.yml"
  16. - "{{ ansible_os_family|lower }}.yml"
  17. - defaults.yml
  18. - name: Include Pre Install tasks if any
  19. include_tasks: "{{ item }}"
  20. with_first_found:
  21. - files:
  22. - "pre-{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.{{ ansible_architecture }}.yml"
  23. - "pre-{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  24. - "pre-{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_release|lower }}-{{ ansible_architecture }}.yml"
  25. - "pre-{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_release|lower }}.yml"
  26. - "pre-{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  27. - "pre-{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_architecture }}.yml"
  28. - "pre-{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}.yml"
  29. - "pre-{{ ansible_os_family|lower | replace('\"_', '') }}-{{ ansible_architecture }}.yml"
  30. - "pre-{{ ansible_os_family|lower | replace('\"_', '') }}.yml"
  31. skip: true
  32. - name: Install mariadb
  33. package:
  34. name: "{{ package_item }}"
  35. state: "present"
  36. disablerepo: "{{ (online_status != 'online') | ternary('*', omit) }}"
  37. enablerepo: "{{ (online_status != 'online') | ternary('yunion-*', omit) }}"
  38. become: true
  39. with_items:
  40. - "{{ packages }}"
  41. loop_control:
  42. loop_var: package_item
  43. - name: Get pip version
  44. shell: |
  45. /usr/bin/python3 -m pip --version | awk '{print $2}'
  46. register: pip_version
  47. # the --break-system-packages is introduced since pip 23.
  48. # this block has been properly tested on all supported platforms as in https://www.cloudpods.org/docs/getting-started/onpremise/quickstart-virt
  49. - name: Pips for mysql/mariadb online
  50. pip:
  51. name: "{{ pip_item }}"
  52. extra_args: "{{ pip_version.stdout is version('23', '>=') | ternary('--break-system-packages', omit) }}"
  53. vars:
  54. ansible_python_interpreter: /usr/bin/python3
  55. when:
  56. - online_status == "online"
  57. become: true
  58. loop: "{{ pips }}"
  59. loop_control:
  60. loop_var: pip_item
  61. - name: pips for mysql/mariadb offline
  62. pip:
  63. name: PyMySQL
  64. extra_args: "--no-index --find-links=file://{{ offline_data_path }}/pips"
  65. become: true
  66. vars:
  67. ansible_python_interpreter: /usr/bin/python3
  68. when:
  69. - online_status == "offline"
  70. - offline_data_path is defined
  71. - offline_data_path | length > 0
  72. - name: Copy my.cnf
  73. copy:
  74. src: my.cnf
  75. dest: /etc/my.cnf
  76. backup: yes
  77. become: true
  78. - name: create Mariadb Conf Path For Debian
  79. file:
  80. path: /etc/my.cnf.d
  81. state: directory
  82. become: true
  83. when: ansible_distribution == "Debian"
  84. - name: make conf dir
  85. file:
  86. name: /etc/my.cnf.d
  87. state: directory
  88. - name: initialize mariadb database
  89. shell:
  90. mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
  91. become: true
  92. when:
  93. - manual_db_init | default(false) == true
  94. - name: enable and start mariadb
  95. systemd:
  96. name: mariadb
  97. enabled: yes
  98. state: started
  99. become: true
  100. - name: Change root password
  101. mysql_user:
  102. login_unix_socket: "{{ login_unix_socket }}"
  103. login_user: "{{ db_user }}"
  104. login_port: "{{ db_port | default(3306) }}"
  105. login_password: "{{ db_password }}"
  106. password: "{{ db_password }}"
  107. name: "{{ db_user }}"
  108. priv: "*.*:ALL,GRANT"
  109. host: "{{ item }}"
  110. check_implicit_admin: true
  111. become: true
  112. vars:
  113. ansible_python_interpreter: /usr/bin/python3
  114. loop:
  115. - "localhost"
  116. - "{{ db_host }}"
  117. - "%"
  118. - "::1"
  119. - "127.0.0.1"
  120. - name: gather os specific Tasks for post installation
  121. include_tasks: "{{ item }}"
  122. with_first_found:
  123. - files:
  124. - "{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.{{ ansible_architecture }}.yml"
  125. - "{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  126. - "{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_release|lower }}-{{ ansible_architecture }}.yml"
  127. - "{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_release|lower }}.yml"
  128. - "{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  129. - "{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}-{{ ansible_architecture }}.yml"
  130. - "{{ ansible_distribution|lower | replace(' ', '_') | replace('\"_', '') }}.yml"
  131. - "{{ ansible_os_family|lower | replace('\"_', '') }}-{{ ansible_architecture }}.yml"
  132. - "{{ ansible_os_family|lower | replace('\"_', '') }}.yml"
  133. - defaults.yml
  134. skip: true