main.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ---
  2. # tasks file
  3. - name: Set main ceph host ip
  4. set_fact:
  5. ceph_main: "{{ hostvars[groups['ceph_servers'][0]]['ansible_host'] }}"
  6. - name: Check ceph status
  7. stat:
  8. path: /var/log/ceph/rgw_start.log
  9. register: ceph_status
  10. - name: Ending if ceph up and running
  11. meta: end_play
  12. when: ceph_status.stat.exists
  13. - name: Include OS specific variables.
  14. include_vars: "{{ ansible_distribution }}.yml"
  15. - name: Install OS specific setup
  16. include_tasks: "setup/{{ ansible_distribution }}.yml"
  17. - name: Set the timezone to the {{ new_host_timezone }} one
  18. timezone: "name={{ new_host_timezone }}"
  19. - name: Make sure ntp is started, and is enabled on restart.
  20. service:
  21. name: chrony
  22. state: started
  23. enabled: yes
  24. masked: no
  25. - name: Bootstrap a new cluster
  26. shell: cephadm bootstrap --mon-ip {{ ansible_host }} --ssh-user {{ cephadm_ssh_user }} >> bootstrap.log
  27. args:
  28. chdir: /var/log/ceph
  29. creates: bootstrap.log
  30. run_once: true
  31. delegate_to: "{{ groups['ceph_servers'][0] }}"
  32. - name: get the cephadm ssh pub key
  33. command: "ceph cephadm get-pub-key"
  34. changed_when: false
  35. run_once: true
  36. register: cephadm_get_pub_key
  37. delegate_to: "{{ groups['ceph_servers'][0] }}"
  38. - name: allow ssh public key for {{ cephadm_ssh_user | default('root') }} account
  39. authorized_key:
  40. user: "{{ cephadm_ssh_user | default('root') }}"
  41. key: "{{ cephadm_get_pub_key.stdout }}"
  42. - name: Restart chronyd
  43. service:
  44. name: chronyd
  45. state: restarted
  46. - name: Pause to build ceph config based on cephadm bootstrap
  47. pause:
  48. minutes: 5
  49. #- name: Ending if ceph status is HEALTH_OK
  50. # block:
  51. # - name: Register ceph status
  52. # shell: ceph status -f json-pretty
  53. # register: ceph_status
  54. # no_log: true
  55. #
  56. # - name: Check ceph status
  57. # meta: end_play
  58. # when: (ceph_status.stdout | from_json).health.status == "HEALTH_OK"
  59. # run_once: true
  60. # delegate_to: "{{ groups['ceph_servers'][0] }}"
  61. - name: Config the new cluster
  62. block:
  63. - name: set cephadm ssh user to {{ cephadm_ssh_user }}
  64. command: "ceph cephadm set-user {{ cephadm_ssh_user | default('root') }}"
  65. changed_when: false
  66. - name: add all ceph hosts
  67. shell: ceph orch host add {{ hostvars[groups['ceph_servers'][host_idx]]['inventory_hostname'] }} {{ hostvars[groups['ceph_servers'][host_idx]]['ansible_host'] }}
  68. when: host_idx != 0
  69. loop: "{{ groups['ceph_servers'] }}"
  70. loop_control:
  71. index_var: host_idx
  72. pause: 2
  73. - name: apply osd all available devices
  74. shell: ceph orch apply osd --all-available-devices
  75. #- name: Copy radosgw.yml file
  76. # template:
  77. # src: radosgw.yml.j2
  78. # dest: /etc/ceph/radosgw.yml
  79. # owner: root
  80. # group: root
  81. # mode: 0644
  82. #- name: Start a S3 Ceph Rados Gateway
  83. # shell: ceph orch apply -i /etc/ceph/radosgw.yml >> rgw_start.log
  84. # args:
  85. # chdir: /var/log/ceph
  86. # creates: rgw_start.log
  87. - name: Start a S3 Ceph Rados Gateway
  88. shell: ceph orch apply rgw s3
  89. - name: Pause to build ceph config based on S3 Rados Gateway
  90. pause:
  91. minutes: 5
  92. - name: set rgw-credentials for dashboard
  93. shell: ceph dashboard set-rgw-credentials
  94. - name: create a radosgw user in order to access the object gateway service
  95. shell: radosgw-admin user create --uid={{ rgw_user }} --display-name={{ rgw_name }} --system
  96. register: user_rgw_json
  97. - name: check user rgw keys
  98. set_fact:
  99. access_key: "{{ (user_rgw_json.stdout | from_json) | json_query('keys[0].access_key') }}"
  100. secret_key: "{{ (user_rgw_json.stdout | from_json) | json_query('keys[0].secret_key') }}"
  101. - name: set user access_key in tmp
  102. shell: echo {{ access_key|string }} > /tmp/access_key
  103. - name: set user secret_key in tmp
  104. shell: echo {{ secret_key|string }} > /tmp/secret_key
  105. - name: set user access_key for dashboard
  106. shell: ceph dashboard set-rgw-api-access-key -i /tmp/access_key
  107. - name: set user secret_key for dashboard
  108. shell: ceph dashboard set-rgw-api-secret-key -i /tmp/secret_key
  109. - name: create a first bucket
  110. amazon.aws.s3_bucket:
  111. name: "{{ rgw_first_bucket }}"
  112. endpoint_url: "http://{{ ceph_main }}:{{ rgw_frontend_port }}"
  113. access_key: "{{ access_key|string }}"
  114. secret_key: "{{ secret_key|string }}"
  115. ceph: true
  116. validate_certs: false
  117. ignore_errors: yes
  118. run_once: true
  119. delegate_to: "{{ groups['ceph_servers'][0] }}"