From 88df105d0b13f2a245666409cafd752d0176ecc3 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Wed, 7 Jun 2017 13:26:04 +0200 Subject: [PATCH] Common: Add ipv6 support e8187f6 does not fix the ipv6 as expected since `ansible_default_*` are filled with the IP address carried by the network interface used by the default gateway route. By the way, it assumes that the MON_IP address will be this IP address which is not always the case. We need to keep using the previous fact but add some intelligence in the template to determine how to retrieve the ipv4|ipv6 address since the path to the fact in `hostvars` is not the same according to ipv4 vs ipv6 case. Fix: 1569 Signed-off-by: Guillaume Abrioux --- .../tasks/checks/check_mandatory_vars.yml | 6 ++ roles/ceph-common/templates/ceph.conf.j2 | 83 +++++++++++-------- roles/ceph-mon/templates/ceph-mon.service.j2 | 13 ++- 3 files changed, 66 insertions(+), 36 deletions(-) diff --git a/roles/ceph-common/tasks/checks/check_mandatory_vars.yml b/roles/ceph-common/tasks/checks/check_mandatory_vars.yml index 114f22ef2..9565383b4 100644 --- a/roles/ceph-common/tasks/checks/check_mandatory_vars.yml +++ b/roles/ceph-common/tasks/checks/check_mandatory_vars.yml @@ -32,3 +32,9 @@ - ceph_origin != 'distro' tags: - package-install + +- name: make sure monitor_interface is defined + fail: + msg: "you must set monitor_interface" + when: + - monitor_interface == 'interface' diff --git a/roles/ceph-common/templates/ceph.conf.j2 b/roles/ceph-common/templates/ceph.conf.j2 index 400baa268..42d111532 100644 --- a/roles/ceph-common/templates/ceph.conf.j2 +++ b/roles/ceph-common/templates/ceph.conf.j2 @@ -30,41 +30,56 @@ mon initial members = {% for host in groups[mon_group_name] %} {% endfor %} {% endif %} -{% if not containerized_deployment and not containerized_deployment_with_kv %} -{% if monitor_address_block %} -mon host = {% for host in groups[mon_group_name] %}{{ hostvars[host]['ansible_all_ipv4_addresses'] | ipaddr(monitor_address_block) | first }}{% if not loop.last %},{% endif %}{% endfor %} -{% elif groups[mon_group_name] is defined %} -mon host = {% for host in groups[mon_group_name] %} - {% set address = hostvars[host]['monitor_address'] if hostvars[host]['monitor_address'] is defined else monitor_address %} - {% set interface = hostvars[host]['monitor_interface'] if hostvars[host]['monitor_interface'] is defined else monitor_interface %} - {% if interface != "interface" %} - {% for key in hostvars[host].keys() %} - {% if hostvars[host][key]['macaddress'] is defined and hostvars[host][key]['device'] is defined and hostvars[host][key]['device'] == interface -%} - {{ hostvars[host][key][ip_version]['address'] }} - {%- endif %} - {% endfor %} - {% elif address != "0.0.0.0" -%} - {{ address }} - {%- endif %} - {%- if not loop.last %},{% endif %} - {% endfor %} -{% endif %} -{% endif %} +{% if not containerized_deployment and not containerized_deployment_with_kv -%} +mon host = {% for host in groups[mon_group_name] -%} + {% if monitor_address_block is defined %} + {% if ip_version == 'ipv4' -%} + {{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }} + {%- elif ip_version == 'ipv6' -%} + [{{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }}] + {%- endif %} + {% elif hostvars[host]['monitor_address'] is defined and hostvars[host]['monitor_address'] != '0.0.0.0' -%} + {% if ip_version == 'ipv4' -%} + {{ hostvars[host]['monitor_address'] }} + {%- elif ip_version == 'ipv6' -%} + [{{ hostvars[host]['monitor_address'] }}] + {%- endif %} + {%- else -%} + {% if ip_version == 'ipv4' -%} + {{ hostvars[host]['ansible_' + monitor_interface][ip_version]['address'] }} + {%- elif ip_version == 'ipv6' -%} + [{{ hostvars[host]['ansible_' + monitor_interface][ip_version][0]['address'] }}] + {%- endif %} + {%- endif %} + {% if not loop.last -%},{%- endif %} + {%- endfor %} +{%- endif %} + {% if containerized_deployment %} fsid = {{ fsid }} -{% if groups[mon_group_name] is defined %} -mon host = {% for host in groups[mon_group_name] %} - {% set interface = ["ansible_",ceph_mon_docker_interface]|join %} - {% if containerized_deployment -%} - {{ hostvars[host][interface]['ipv4']['address'] }} - {%- elif hostvars[host]['monitor_address'] is defined -%} - {{ hostvars[host]['monitor_address'] }} - {%- elif monitor_address != "0.0.0.0" -%} - {{ monitor_address }} - {%- endif %} - {%- if not loop.last %},{% endif %} - {% endfor %} -{% endif %} +mon host = {% for host in groups[mon_group_name] -%} + {% if monitor_address_block is defined %} + {% if ip_version == 'ipv4' -%} + {{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }} + {%- elif ip_version == 'ipv6' -%} + [{{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }}] + {%- endif %} + {% elif hostvars[host]['monitor_address'] is defined and hostvars[host]['monitor_address'] != '0.0.0.0' -%} + {% if ip_version == 'ipv4' -%} + {{ hostvars[host]['monitor_address'] }} + {%- elif ip_version == 'ipv6' -%} + [{{ hostvars[host]['monitor_address'] }}] + {%- endif %} + {%- else -%} + {% set interface = ["ansible_",ceph_mon_docker_interface]|join %} + {% if ip_version == 'ipv4' -%} + {{ hostvars[host][interface][ip_version]['address'] }} + {%- elif ip_version == 'ipv6' -%} + [{{ hostvars[host][interface][ip_version][0]['address'] }}] + {%- endif %} + {%- endif %} + {% if not loop.last -%},{%- endif %} + {%- endfor %} {% endif %} {% if public_network is defined %} @@ -85,12 +100,10 @@ admin socket = {{ rbd_client_admin_socket_path }}/$cluster-$type.$id.$pid.$cctid log file = {{ rbd_client_log_file }} # must be writable by QEMU and allowed by SELinux or AppArmor [osd] -{% if osd_objectstore != 'bluestore' %} osd mkfs type = {{ osd_mkfs_type }} osd mkfs options xfs = {{ osd_mkfs_options_xfs }} osd mount options xfs = {{ osd_mount_options_xfs }} osd journal size = {{ journal_size }} -{% endif %} {% if filestore_xattr_use_omap != None %} filestore xattr use omap = {{ filestore_xattr_use_omap }} {% elif osd_mkfs_type == "ext4" %} diff --git a/roles/ceph-mon/templates/ceph-mon.service.j2 b/roles/ceph-mon/templates/ceph-mon.service.j2 index daaebdfd7..74457aa2e 100644 --- a/roles/ceph-mon/templates/ceph-mon.service.j2 +++ b/roles/ceph-mon/templates/ceph-mon.service.j2 @@ -23,8 +23,19 @@ ExecStart=/usr/bin/docker run --rm --name ceph-mon-%i --net=host \ --net=host \ {% endif -%} -e CEPH_DAEMON=MON \ - -e MON_IP={{ hostvars[inventory_hostname]['ansible_default_' + ip_version]['address'] }} \ -e CEPH_PUBLIC_NETWORK={{ ceph_mon_docker_subnet }} \ + -e IP_VERSION={{ ip_version[-1:] }} \ + {% if monitor_address is defined and monitor_address != '0.0.0.0' %} + {% if ip_version == 'ipv4' -%} + -e MON_IP={{ monitor_address }} \ + {% elif ip_version == 'ipv6' -%} + -e MON_IP=[{{ monitor_address }}] \ + {% endif -%} + {% elif ip_version == 'ipv4' -%} + -e MON_IP={{ hostvars[inventory_hostname]['ansible_' + ceph_mon_docker_interface][ip_version]['address'] }} \ + {% elif ip_version =='ipv6' -%} + -e MON_IP=[{{ hostvars[inventory_hostname]['ansible_' + ceph_mon_docker_interface][ip_version][0]['address'] }}] \ + {% endif -%} {{ ceph_mon_docker_extra_env }} \ {{ceph_docker_registry }}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} ExecStopPost=-/usr/bin/docker stop ceph-mon-%i -- 2.39.5