2016-04-27 21:17:56 +08:00
|
|
|
---
|
2018-03-21 03:13:28 +08:00
|
|
|
- name: check if it is atomic host
|
|
|
|
stat:
|
|
|
|
path: /run/ostree-booted
|
|
|
|
register: stat_ostree
|
|
|
|
|
|
|
|
- name: set_fact is_atomic
|
|
|
|
set_fact:
|
|
|
|
is_atomic: "{{ stat_ostree.stat.exists }}"
|
|
|
|
|
2019-11-26 23:10:17 +08:00
|
|
|
- name: import_tasks container_binary.yml
|
|
|
|
import_tasks: container_binary.yml
|
2018-11-08 17:02:37 +08:00
|
|
|
|
2019-08-22 23:46:05 +08:00
|
|
|
# In case ansible_python_interpreter is set by the user,
|
2019-09-04 15:56:10 +08:00
|
|
|
# ansible will not discover python and discovered_interpreter_python
|
2019-08-22 23:46:05 +08:00
|
|
|
# will not be set
|
2019-09-04 15:56:10 +08:00
|
|
|
- name: set_fact discovered_interpreter_python
|
2019-08-22 23:46:05 +08:00
|
|
|
set_fact:
|
2019-09-04 15:56:10 +08:00
|
|
|
discovered_interpreter_python: "{{ ansible_python_interpreter }}"
|
2019-08-22 23:46:05 +08:00
|
|
|
when: ansible_python_interpreter is defined
|
|
|
|
|
2019-01-08 17:57:51 +08:00
|
|
|
# Set ceph_release to ceph_stable by default
|
|
|
|
- name: set_fact ceph_release ceph_stable_release
|
|
|
|
set_fact:
|
|
|
|
ceph_release: "{{ ceph_stable_release }}"
|
|
|
|
|
2017-09-15 06:48:53 +08:00
|
|
|
- name: set_fact monitor_name ansible_hostname
|
|
|
|
set_fact:
|
2020-04-09 20:48:53 +08:00
|
|
|
monitor_name: "{{ hostvars[item]['ansible_hostname'] }}"
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
delegate_facts: true
|
|
|
|
with_items: "{{ groups.get(mon_group_name, []) }}"
|
|
|
|
run_once: true
|
|
|
|
when: groups.get(mon_group_name, []) | length > 0
|
2016-04-27 21:17:56 +08:00
|
|
|
|
2020-01-13 22:30:13 +08:00
|
|
|
- name: find a running monitor
|
|
|
|
when: groups.get(mon_group_name, []) | length > 0
|
|
|
|
block:
|
|
|
|
- name: set_fact container_exec_cmd
|
|
|
|
set_fact:
|
|
|
|
container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] if not rolling_update else hostvars[mon_host | default(groups[mon_group_name][0])]['ansible_hostname'] }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment | bool
|
|
|
|
|
|
|
|
- name: find a running mon container
|
|
|
|
command: "{{ container_binary }} ps -q --filter name=ceph-mon-{{ hostvars[item]['ansible_hostname'] }}"
|
|
|
|
register: find_running_mon_container
|
|
|
|
failed_when: false
|
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
with_items: "{{ groups.get(mon_group_name, []) }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment | bool
|
|
|
|
|
|
|
|
- name: check for a ceph mon socket
|
|
|
|
shell: stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mon*.asok
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
check_mode: no
|
|
|
|
register: mon_socket_stat
|
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
with_items: "{{ groups.get(mon_group_name, []) }}"
|
|
|
|
when:
|
|
|
|
- not containerized_deployment | bool
|
|
|
|
|
|
|
|
- name: check if the ceph mon socket is in-use
|
|
|
|
command: grep -q {{ item.stdout }} /proc/net/unix
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
check_mode: no
|
|
|
|
register: mon_socket
|
|
|
|
run_once: true
|
|
|
|
with_items: "{{ mon_socket_stat.results }}"
|
|
|
|
when:
|
|
|
|
- not containerized_deployment | bool
|
|
|
|
- item.rc == 0
|
|
|
|
|
|
|
|
- name: set_fact running_mon - non_container
|
|
|
|
set_fact:
|
|
|
|
running_mon: "{{ hostvars[item.item.item]['inventory_hostname'] }}"
|
|
|
|
with_items: "{{ mon_socket.results }}"
|
|
|
|
run_once: true
|
|
|
|
when:
|
|
|
|
- not containerized_deployment | bool
|
|
|
|
- item.rc is defined
|
2020-01-23 16:58:18 +08:00
|
|
|
- item.rc == 0
|
2020-01-13 22:30:13 +08:00
|
|
|
|
|
|
|
- name: set_fact running_mon - container
|
|
|
|
set_fact:
|
|
|
|
running_mon: "{{ item.item }}"
|
|
|
|
run_once: true
|
|
|
|
with_items: "{{ find_running_mon_container.results }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment | bool
|
|
|
|
- item.stdout_lines | default([]) | length > 0
|
|
|
|
|
|
|
|
- name: set_fact _container_exec_cmd
|
|
|
|
set_fact:
|
2020-01-29 10:34:24 +08:00
|
|
|
_container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ hostvars[groups[mon_group_name][0] if running_mon is undefined else running_mon]['ansible_hostname'] }}"
|
2020-01-13 22:30:13 +08:00
|
|
|
when:
|
|
|
|
- containerized_deployment | bool
|
|
|
|
|
|
|
|
# this task shouldn't run in a rolling_update situation
|
|
|
|
# because it blindly picks a mon, which may be down because
|
|
|
|
# of the rolling update
|
|
|
|
- name: is ceph running already?
|
|
|
|
command: "{{ timeout_command }} {{ _container_exec_cmd | default('') }} ceph --cluster {{ cluster }} -s -f json"
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
check_mode: no
|
|
|
|
register: ceph_current_status
|
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] if running_mon is undefined else running_mon }}"
|
|
|
|
when:
|
|
|
|
- not rolling_update | bool
|
2017-02-18 04:29:45 +08:00
|
|
|
|
|
|
|
# set this as a default when performing a rolling_update
|
|
|
|
# so the rest of the tasks here will succeed
|
2018-08-22 02:50:31 +08:00
|
|
|
- name: set_fact ceph_current_status rc 1
|
2017-09-15 06:48:53 +08:00
|
|
|
set_fact:
|
2018-08-22 02:50:31 +08:00
|
|
|
ceph_current_status:
|
2017-02-18 04:29:45 +08:00
|
|
|
rc: 1
|
2019-04-01 23:46:15 +08:00
|
|
|
when: rolling_update or groups.get(mon_group_name, []) | length == 0
|
2016-12-06 22:59:49 +08:00
|
|
|
|
2016-12-08 23:58:22 +08:00
|
|
|
- name: create a local fetch directory if it does not exist
|
2018-11-01 19:50:31 +08:00
|
|
|
file:
|
syntax: change local_action syntax
Use a nicer syntax for `local_action` tasks.
We used to have oneliner like this:
```
local_action: wait_for port=22 host={{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }} state=started delay=10 timeout=500 }}
```
The usual syntax:
```
local_action:
module: wait_for
port: 22
host: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
state: started
delay: 10
timeout: 500
```
is nicer and kind of way to keep consistency regarding the whole
playbook.
This also fix a potential issue about missing quotation :
```
Traceback (most recent call last):
File "/tmp/ansible_wQtWsi/ansible_module_command.py", line 213, in <module>
main()
File "/tmp/ansible_wQtWsi/ansible_module_command.py", line 185, in main
rc, out, err = module.run_command(args, executable=executable, use_unsafe_shell=shell, encoding=None, data=stdin)
File "/tmp/ansible_wQtWsi/ansible_modlib.zip/ansible/module_utils/basic.py", line 2710, in run_command
File "/usr/lib64/python2.7/shlex.py", line 279, in split
return list(lex) File "/usr/lib64/python2.7/shlex.py", line 269, in next
token = self.get_token()
File "/usr/lib64/python2.7/shlex.py", line 96, in get_token
raw = self.read_token()
File "/usr/lib64/python2.7/shlex.py", line 172, in read_token
raise ValueError, "No closing quotation"
ValueError: No closing quotation
```
writing `local_action: shell echo {{ fsid }} | tee {{ fetch_directory }}/ceph_cluster_uuid.conf`
can cause trouble because it's complaining with missing quotes, this fix solves this issue.
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1510555
Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
2018-01-31 16:23:28 +08:00
|
|
|
path: "{{ fetch_directory }}"
|
|
|
|
state: directory
|
2018-11-01 19:50:31 +08:00
|
|
|
delegate_to: localhost
|
2016-12-08 23:58:22 +08:00
|
|
|
changed_when: false
|
|
|
|
become: false
|
2019-05-22 16:02:42 +08:00
|
|
|
when: cephx | bool or generate_fsid | bool
|
2016-12-08 23:58:22 +08:00
|
|
|
|
2019-03-21 01:34:47 +08:00
|
|
|
- name: get current fsid
|
2019-10-02 02:41:57 +08:00
|
|
|
command: "{{ timeout_command }} {{ container_exec_cmd }} ceph --admin-daemon /var/run/ceph/{{ cluster }}-mon.{{ hostvars[mon_host | default(groups[mon_group_name][0])]['ansible_hostname'] }}.asok config get fsid"
|
2019-03-21 01:34:47 +08:00
|
|
|
register: rolling_update_fsid
|
|
|
|
delegate_to: "{{ mon_host | default(groups[mon_group_name][0]) }}"
|
2019-06-20 20:45:07 +08:00
|
|
|
until: rolling_update_fsid is succeeded
|
2019-05-22 16:02:42 +08:00
|
|
|
when: rolling_update | bool
|
2019-03-21 01:34:47 +08:00
|
|
|
|
|
|
|
- name: set_fact fsid
|
|
|
|
set_fact:
|
|
|
|
fsid: "{{ (rolling_update_fsid.stdout | from_json).fsid }}"
|
2019-05-22 16:02:42 +08:00
|
|
|
when: rolling_update | bool
|
2019-03-21 01:34:47 +08:00
|
|
|
|
2018-08-22 02:50:31 +08:00
|
|
|
- name: set_fact ceph_current_status (convert to json)
|
2017-09-15 06:48:53 +08:00
|
|
|
set_fact:
|
2018-08-22 02:50:31 +08:00
|
|
|
ceph_current_status: "{{ ceph_current_status.stdout | from_json }}"
|
2017-02-18 04:29:45 +08:00
|
|
|
when:
|
2019-05-22 16:02:42 +08:00
|
|
|
- not rolling_update | bool
|
2018-08-22 02:50:31 +08:00
|
|
|
- ceph_current_status.rc == 0
|
|
|
|
|
|
|
|
- name: set_fact fsid from ceph_current_status
|
|
|
|
set_fact:
|
|
|
|
fsid: "{{ ceph_current_status.fsid }}"
|
2019-04-01 23:46:15 +08:00
|
|
|
when: ceph_current_status.fsid is defined
|
2016-12-06 22:59:49 +08:00
|
|
|
|
2019-08-22 23:39:47 +08:00
|
|
|
- name: fsid related tasks
|
2019-03-28 16:13:30 +08:00
|
|
|
when:
|
2019-05-22 16:02:42 +08:00
|
|
|
- generate_fsid | bool
|
2019-03-28 16:13:30 +08:00
|
|
|
- ceph_current_status.fsid is undefined
|
2019-05-22 16:02:42 +08:00
|
|
|
- not rolling_update | bool
|
2019-03-28 16:13:30 +08:00
|
|
|
block:
|
2019-01-08 17:57:51 +08:00
|
|
|
- name: generate cluster fsid
|
2020-01-08 21:14:41 +08:00
|
|
|
command: "{{ hostvars[groups[mon_group_name][0]]['discovered_interpreter_python'] }} -c 'import uuid; print(str(uuid.uuid4()))'"
|
2019-01-08 17:57:51 +08:00
|
|
|
register: cluster_uuid
|
2019-06-01 01:26:30 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2019-01-08 17:57:51 +08:00
|
|
|
run_once: true
|
2016-12-08 23:58:22 +08:00
|
|
|
|
2019-01-08 17:57:51 +08:00
|
|
|
- name: set_fact fsid
|
|
|
|
set_fact:
|
|
|
|
fsid: "{{ cluster_uuid.stdout }}"
|
2016-12-08 23:58:22 +08:00
|
|
|
|
2017-09-15 06:48:53 +08:00
|
|
|
- name: set_fact mds_name ansible_hostname
|
|
|
|
set_fact:
|
2016-05-09 06:36:15 +08:00
|
|
|
mds_name: "{{ ansible_hostname }}"
|
2016-12-09 21:51:35 +08:00
|
|
|
|
2017-09-28 06:17:12 +08:00
|
|
|
- name: resolve device link(s)
|
|
|
|
command: readlink -f {{ item }}
|
|
|
|
changed_when: false
|
2019-05-06 16:14:36 +08:00
|
|
|
check_mode: no
|
2017-09-28 06:17:12 +08:00
|
|
|
with_items: "{{ devices }}"
|
|
|
|
register: devices_prepare_canonicalize
|
|
|
|
when:
|
2018-05-02 00:22:31 +08:00
|
|
|
- devices is defined
|
2017-09-28 06:17:12 +08:00
|
|
|
- inventory_hostname in groups.get(osd_group_name, [])
|
2019-05-22 16:02:42 +08:00
|
|
|
- not osd_auto_discovery | default(False) | bool
|
2017-09-28 06:17:12 +08:00
|
|
|
|
|
|
|
- name: set_fact build devices from resolved symlinks
|
|
|
|
set_fact:
|
|
|
|
devices: "{{ devices | default([]) + [ item.stdout ] }}"
|
|
|
|
with_items: "{{ devices_prepare_canonicalize.results }}"
|
|
|
|
when:
|
2018-05-02 00:22:31 +08:00
|
|
|
- devices is defined
|
2017-09-28 06:17:12 +08:00
|
|
|
- inventory_hostname in groups.get(osd_group_name, [])
|
2019-05-22 16:02:42 +08:00
|
|
|
- not osd_auto_discovery | default(False) | bool
|
2017-09-28 06:17:12 +08:00
|
|
|
|
|
|
|
- name: set_fact build final devices list
|
|
|
|
set_fact:
|
|
|
|
devices: "{{ devices | reject('search','/dev/disk') | list | unique }}"
|
|
|
|
when:
|
2018-05-02 00:22:31 +08:00
|
|
|
- devices is defined
|
2017-09-28 06:17:12 +08:00
|
|
|
- inventory_hostname in groups.get(osd_group_name, [])
|
2019-05-22 16:02:42 +08:00
|
|
|
- not osd_auto_discovery | default(False) | bool
|
2017-11-23 05:38:30 +08:00
|
|
|
|
2019-01-11 01:26:19 +08:00
|
|
|
- name: set_fact devices generate device list when osd_auto_discovery
|
|
|
|
set_fact:
|
2019-11-20 18:02:49 +08:00
|
|
|
devices: "{{ (devices | default([]) + [ item.key | regex_replace('^', '/dev/') ]) | unique }}"
|
2019-01-11 01:26:19 +08:00
|
|
|
with_dict: "{{ ansible_devices }}"
|
|
|
|
when:
|
2019-05-22 16:02:42 +08:00
|
|
|
- osd_auto_discovery | default(False) | bool
|
2020-01-17 03:03:09 +08:00
|
|
|
- inventory_hostname in groups.get(osd_group_name, [])
|
2019-01-11 01:26:19 +08:00
|
|
|
- ansible_devices is defined
|
|
|
|
- item.value.removable == "0"
|
|
|
|
- item.value.sectors != "0"
|
|
|
|
- item.value.partitions|count == 0
|
|
|
|
- item.value.holders|count == 0
|
2019-02-26 07:07:01 +08:00
|
|
|
- item.key is not match osd_auto_discovery_exclude
|
2019-01-11 01:26:19 +08:00
|
|
|
|
2018-04-14 01:42:17 +08:00
|
|
|
- name: set_fact ceph_uid for debian based system - non container
|
|
|
|
set_fact:
|
|
|
|
ceph_uid: 64045
|
|
|
|
when:
|
2019-05-22 16:02:42 +08:00
|
|
|
- not containerized_deployment | bool
|
2018-04-14 01:42:17 +08:00
|
|
|
- ansible_os_family == 'Debian'
|
|
|
|
|
2018-09-05 19:20:47 +08:00
|
|
|
- name: set_fact rgw_hostname
|
2018-08-22 02:50:31 +08:00
|
|
|
set_fact:
|
2018-09-05 19:20:47 +08:00
|
|
|
rgw_hostname: "{% set _value = ansible_hostname -%}
|
2018-11-20 18:46:08 +08:00
|
|
|
{% for key in (ceph_current_status['servicemap']['services']['rgw']['daemons'] | list) -%}
|
2018-09-05 19:20:47 +08:00
|
|
|
{% if key == ansible_fqdn -%}
|
|
|
|
{% set _value = key -%}
|
|
|
|
{% endif -%}
|
|
|
|
{% endfor -%}
|
|
|
|
{{ _value }}"
|
2018-08-22 02:50:31 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups.get(rgw_group_name, []) or inventory_hostname in groups.get(nfs_group_name, [])
|
|
|
|
- ceph_current_status['servicemap'] is defined
|
|
|
|
- ceph_current_status['servicemap']['services'] is defined
|
2018-10-11 03:24:22 +08:00
|
|
|
- ceph_current_status['servicemap']['services']['rgw'] is defined
|
2018-10-03 22:09:33 +08:00
|
|
|
|
2018-11-13 22:40:35 +08:00
|
|
|
- name: set_fact osd_pool_default_pg_num
|
|
|
|
set_fact:
|
|
|
|
osd_pool_default_pg_num: "{{ ceph_conf_overrides.get('global', {}).get('osd_pool_default_pg_num', ceph_osd_pool_default_pg_num) }}"
|
|
|
|
|
2018-11-21 18:00:11 +08:00
|
|
|
- name: set_fact osd_pool_default_size
|
|
|
|
set_fact:
|
|
|
|
osd_pool_default_size: "{{ ceph_conf_overrides.get('global', {}).get('osd_pool_default_size', ceph_osd_pool_default_size) }}"
|
|
|
|
|
2019-03-01 04:58:31 +08:00
|
|
|
- name: set_fact osd_pool_default_min_size
|
|
|
|
set_fact:
|
|
|
|
osd_pool_default_min_size: "{{ ceph_conf_overrides.get('global', {}).get('osd_pool_default_min_size', ceph_osd_pool_default_min_size) }}"
|
|
|
|
|
2019-03-08 06:14:12 +08:00
|
|
|
- name: check if the ceph conf exists
|
|
|
|
stat:
|
|
|
|
path: '/etc/ceph/{{ cluster }}.conf'
|
|
|
|
register: ceph_conf
|
|
|
|
|
|
|
|
- name: get default crush rule value from ceph configuration
|
|
|
|
command: grep 'osd pool default crush rule' /etc/ceph/{{ cluster }}.conf
|
|
|
|
register: crush_rule_variable
|
|
|
|
changed_when: false
|
2019-05-06 16:14:36 +08:00
|
|
|
check_mode: no
|
2019-03-08 06:14:12 +08:00
|
|
|
failed_when: false
|
|
|
|
when: ceph_conf.stat.exists
|
|
|
|
|
|
|
|
- name: set_fact osd_pool_default_crush_rule
|
|
|
|
set_fact:
|
2020-03-27 23:21:09 +08:00
|
|
|
osd_pool_default_crush_rule: "{{ crush_rule_variable.stdout.split(' = ')[1] if crush_rule_variable.get('rc', 1) | int == 0 else ceph_osd_pool_default_crush_rule }}"
|
2019-03-08 06:14:12 +08:00
|
|
|
|
2018-10-03 22:09:33 +08:00
|
|
|
- name: import_tasks set_monitor_address.yml
|
|
|
|
import_tasks: set_monitor_address.yml
|
2019-05-07 22:42:49 +08:00
|
|
|
when: groups.get(mon_group_name, []) | length > 0
|
2018-10-03 22:09:33 +08:00
|
|
|
|
|
|
|
- name: import_tasks set_radosgw_address.yml
|
|
|
|
import_tasks: set_radosgw_address.yml
|
2019-04-01 23:46:15 +08:00
|
|
|
when: inventory_hostname in groups.get(rgw_group_name, [])
|
2018-11-09 08:56:57 +08:00
|
|
|
|
2019-07-02 21:30:12 +08:00
|
|
|
- name: set_fact use_new_ceph_iscsi package or old ceph-iscsi-config/cli
|
|
|
|
set_fact:
|
2019-08-22 23:39:47 +08:00
|
|
|
use_new_ceph_iscsi: "{{ (gateway_ip_list == '0.0.0.0' and gateway_iqn | length == 0 and client_connections | length == 0 and rbd_devices | length == 0) | bool | ternary(true, false) }}"
|
2019-12-11 05:35:34 +08:00
|
|
|
when: iscsi_gw_group_name in group_names
|
2020-03-27 23:21:09 +08:00
|
|
|
|
2020-04-10 07:02:06 +08:00
|
|
|
- name: set_fact ceph_run_cmd
|
|
|
|
set_fact:
|
|
|
|
ceph_run_cmd: "{{ container_binary + ' run --rm --net=host -v /etc/ceph:/etc/ceph:z -v /var/lib/ceph/:/var/lib/ceph/:z -v /var/log/ceph/:/var/log/ceph/:z --entrypoint=ceph ' + ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else 'ceph' }}"
|
|
|
|
|
2020-03-27 23:21:09 +08:00
|
|
|
- name: set_fact ceph_admin_command
|
|
|
|
set_fact:
|
2020-04-10 07:02:06 +08:00
|
|
|
ceph_admin_command: "{{ ceph_run_cmd }} -n client.admin -k /etc/ceph/{{ cluster }}.client.admin.keyring"
|