2016-05-11 00:29:27 +08:00
---
2018-04-10 21:39:44 +08:00
- name : set_fact keys_tmp - preserve backward compatibility after the introduction of the ceph_keys module
set_fact :
2018-09-07 22:54:42 +08:00
keys_tmp : "{{ keys_tmp|default([]) + [ { 'key': item.key, 'name': item.name, 'caps': { 'mon': item.mon_cap, 'osd': item.osd_cap|default(''), 'mds': item.mds_cap|default(''), 'mgr': item.mgr_cap|default('') } , 'mode': item.mode } ] }}"
2018-04-10 21:39:44 +08:00
when :
- item.get('mon_cap', None) # it's enough to assume we are running an old-fashionned syntax simply by checking the presence of mon_cap since every key needs this cap
with_items : "{{ keys }}"
- name : set_fact keys - override keys_tmp with keys
set_fact :
keys : "{{ keys_tmp }}"
when :
- keys_tmp is defined
2018-08-30 15:53:36 +08:00
# dummy container setup is only supported on x86_64
# when running with containerized_deployment: true this task
# creates a group that contains only x86_64 hosts.
# when running with containerized_deployment: false this task
# will add all client hosts to the group (and not filter).
- name : create filtered clients group
add_host :
name : "{{ item }}"
groups : _filtered_clients
with_items : "{{ groups[client_group_name] }}"
when :
- (hostvars[item]['ansible_architecture'] == 'x86_64') or (not containerized_deployment)
2018-04-04 22:22:36 +08:00
- name : run a dummy container (sleep 300) from where we can create pool(s)/key(s)
command : >
2018-11-08 17:02:37 +08:00
{{ container_binary }} run \
2018-04-17 20:16:41 +08:00
--rm \
2018-04-04 22:22:36 +08:00
-d \
2018-04-17 21:32:53 +08:00
-v {{ ceph_conf_key_directory }}:{{ ceph_conf_key_directory }}:z \
2018-04-04 22:22:36 +08:00
--name ceph-create-keys \
--entrypoint=sleep \
2018-10-05 21:36:36 +08:00
{{ ceph_client_docker_registry}}/{{ ceph_client_docker_image }}:{{ ceph_client_docker_image_tag }} \
2018-04-04 22:22:36 +08:00
300
changed_when : false
2018-06-08 14:49:37 +08:00
when :
- containerized_deployment
2018-08-30 15:53:36 +08:00
- inventory_hostname == groups.get('_filtered_clients') | first
2017-09-14 04:13:53 +08:00
2018-05-01 02:53:42 +08:00
- name : set_fact delegated_node
set_fact :
delegated_node : "{{ groups[mon_group_name][0] if groups.get(mon_group_name, []) | length > 0 else inventory_hostname }}"
- name : set_fact condition_copy_admin_key
set_fact :
condition_copy_admin_key : "{{ True if groups.get(mon_group_name, []) | length > 0 else copy_admin_key }}"
- name : set_fact docker_exec_cmd
set_fact :
2018-11-08 17:02:37 +08:00
docker_exec_cmd : "{{ container_binary }} exec {% if groups.get(mon_group_name, []) | length > 0 -%} ceph-mon-{{ hostvars[delegated_node]['ansible_hostname'] }} {% else %} ceph-create-keys {% endif %}"
2018-05-01 02:53:42 +08:00
when :
- containerized_deployment
2018-04-04 22:22:36 +08:00
- name : create cephx key(s)
ceph_key :
state : present
name : "{{ item.name }}"
caps : "{{ item.caps }}"
secret : "{{ item.key | default('') }}"
2018-06-06 19:59:26 +08:00
containerized : "{{ docker_exec_cmd | default('') }}"
2018-04-04 22:22:36 +08:00
cluster : "{{ cluster }}"
dest : "{{ ceph_conf_key_directory }}"
2018-07-11 22:03:10 +08:00
import_key : "{{ condition_copy_admin_key }}"
2018-04-20 22:37:05 +08:00
mode : "{{ item.mode|default(omit) }}"
2016-11-03 17:16:33 +08:00
with_items : "{{ keys }}"
2018-06-06 19:59:26 +08:00
delegate_to : "{{ delegated_node }}"
2017-07-13 23:39:35 +08:00
when :
- cephx
- keys | length > 0
2018-08-30 15:53:36 +08:00
- inventory_hostname == groups.get('_filtered_clients') | first
2017-07-13 23:39:35 +08:00
2018-04-04 22:22:36 +08:00
- name : slurp client cephx key(s)
2018-03-30 19:48:17 +08:00
slurp :
src : "{{ ceph_conf_key_directory }}/{{ cluster }}.{{ item.name }}.keyring"
with_items :
- "{{ keys }}"
register : slurp_client_keys
2018-06-06 19:59:26 +08:00
delegate_to : "{{ delegated_node }}"
2018-03-30 19:48:17 +08:00
when :
- cephx
- keys | length > 0
2018-08-30 15:53:36 +08:00
- inventory_hostname == groups.get('_filtered_clients') | first
2018-03-30 19:48:17 +08:00
2018-10-01 23:11:13 +08:00
- name : pool related tasks
2018-04-27 20:48:33 +08:00
when :
2018-05-01 02:53:42 +08:00
- condition_copy_admin_key
2018-08-30 15:53:36 +08:00
- inventory_hostname == groups.get('_filtered_clients', []) | first
2018-10-01 23:11:13 +08:00
block :
- name : list existing pool(s)
command : >
{{ docker_exec_cmd | default('') }} ceph --cluster {{ cluster }}
osd pool get {{ item.name }} size
with_items : "{{ pools }}"
register : created_pools
failed_when : false
delegate_to : "{{ delegated_node }}"
2018-04-27 20:48:33 +08:00
2018-10-01 23:11:13 +08:00
- name : create ceph pool(s)
command : >
{{ docker_exec_cmd | default('') }} ceph --cluster {{ cluster }}
osd pool create {{ item.0.name }}
2018-11-13 22:40:35 +08:00
{{ item.0.pg_num | default(osd_pool_default_pg_num) }}
{{ item.0.pgp_num | default(item.0.pg_num) | default(osd_pool_default_pg_num) }}
2018-11-01 23:03:16 +08:00
{{ 'replicated_rule' if not item.0.rule_name | default('replicated_rule') else item.0.rule_name | default('replicated_rule') }}
2018-10-01 23:11:13 +08:00
{{ 1 if item.0.type|default(1) == 'replicated' else 3 if item.0.type|default(1) == 'erasure' else item.0.type|default(1) }}
2018-11-01 23:03:16 +08:00
{%- if (item.0.type | default("1") == '3' or item.0.type | default("1") == 'erasure') and item.0.erasure_profile %}
2018-10-01 23:11:13 +08:00
{{ item.0.erasure_profile }}
{%- endif %}
{{ item.0.expected_num_objects | default('') }}
with_together :
- "{{ pools }}"
- "{{ created_pools.results }}"
changed_when : false
delegate_to : "{{ delegated_node }}"
when :
- pools | length > 0
- item.1.rc != 0
- name : customize pool size
command : >
{{ docker_exec_cmd | default('') }} ceph --cluster {{ cluster }}
2018-11-21 18:00:11 +08:00
osd pool set {{ item.name }} size {{ item.size | default(osd_pool_default_size) }}
2018-10-01 23:11:13 +08:00
with_items : "{{ pools | unique }}"
2018-11-18 00:40:35 +08:00
delegate_to : "{{ delegated_node }}"
2018-10-01 23:11:13 +08:00
changed_when : false
when :
- pools | length > 0
2018-11-21 18:00:11 +08:00
- item.size | default(osd_pool_default_size) != ceph_osd_pool_default_size
2017-09-14 04:13:53 +08:00
2018-04-04 22:22:36 +08:00
- name : get client cephx keys
2018-03-30 19:48:17 +08:00
copy :
dest : "{{ item.source }}"
content : "{{ item.content | b64decode }}"
2018-06-07 21:49:03 +08:00
mode : "{{ item.item.get('mode', '0600') }}"
2018-04-23 16:02:16 +08:00
owner : "{{ ceph_uid }}"
group : "{{ ceph_uid }}"
2018-03-30 19:48:17 +08:00
with_items :
2018-08-30 15:53:36 +08:00
- "{{ hostvars[groups['_filtered_clients'][0]]['slurp_client_keys']['results'] }}"
2018-03-30 19:48:17 +08:00
when :
- not item.get('skipped', False)