aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/nova-cell/tasks/external_ceph.yml
blob: 9f4fe9cbc61606bd88dbd497035e414ba2050289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
---
- name: Check nova keyring file
  vars:
    keyring: "{{ nova_cell_ceph_backend['cluster'] }}.client.{{ nova_cell_ceph_backend['vms']['user'] }}.keyring"
    paths:
      - "{{ node_custom_config }}/nova/{{ inventory_hostname }}/{{ keyring }}"
      - "{{ node_custom_config }}/nova/{{ keyring }}"
  stat:
    path: "{{ lookup('first_found', paths) }}"
  delegate_to: localhost
  register: nova_cephx_keyring_file
  failed_when: not nova_cephx_keyring_file.stat.exists
  when:
    - nova_backend == "rbd"
    - external_ceph_cephx_enabled | bool

- name: Check cinder keyring file
  vars:
    keyring: "{{ nova_cell_ceph_backend['cluster'] }}.client.{{ nova_cell_ceph_backend['volumes']['user'] }}.keyring"
    paths:
      - "{{ node_custom_config }}/nova/{{ inventory_hostname }}/{{ keyring }}"
      - "{{ node_custom_config }}/nova/{{ keyring }}"
  stat:
    path: "{{ lookup('first_found', paths) }}"
  delegate_to: localhost
  register: cinder_cephx_keyring_file
  failed_when: not cinder_cephx_keyring_file.stat.exists
  when:
    - cinder_backend_ceph | bool
    - external_ceph_cephx_enabled | bool

- name: Extract nova key from file
  set_fact:
    nova_cephx_raw_key:
      "{{ lookup('template', nova_cephx_keyring_file.stat.path) | regex_search('key\\s*=.*$', multiline=True) | regex_replace('key\\s*=\\s*(.*)\\s*', '\\1') }}"
  changed_when: false
  when:
    - nova_backend == "rbd"
    - external_ceph_cephx_enabled | bool

- name: Extract cinder key from file
  set_fact:
    cinder_cephx_raw_key:
      "{{ lookup('template', cinder_cephx_keyring_file.stat.path) | regex_search('key\\s*=.*$', multiline=True) | regex_replace('key\\s*=\\s*(.*)\\s*', '\\1') }}"
  changed_when: false
  when:
    - cinder_backend_ceph | bool
    - external_ceph_cephx_enabled | bool

- name: Copy over ceph nova keyring file
  template:
    src: "{{ nova_cephx_keyring_file.stat.path }}"
    dest: "{{ node_config_directory }}/{{ item }}/"
    owner: "{{ config_owner_user }}"
    group: "{{ config_owner_group }}"
    mode: "0660"
  become: true
  with_items:
    - nova-compute
  when:
    - inventory_hostname in groups[nova_cell_compute_group]
    - nova_backend == "rbd"
    - external_ceph_cephx_enabled | bool

- name: Copy over ceph cinder keyring file
  template:
    src: "{{ cinder_cephx_keyring_file.stat.path }}"
    dest: "{{ node_config_directory }}/{{ item }}/"
    owner: "{{ config_owner_user }}"
    group: "{{ config_owner_group }}"
    mode: "0660"
  become: true
  with_items:  # NOTE: nova-libvirt does not need it
    - nova-compute
  when:
    - inventory_hostname in groups[nova_cell_compute_group]
    - nova_backend == "rbd"
    - external_ceph_cephx_enabled | bool

- name: Copy over ceph.conf
  vars:
    service: "{{ nova_cell_services[item] }}"
    paths:
      - "{{ node_custom_config }}/nova/{{ inventory_hostname }}/{{ nova_cell_ceph_backend['cluster'] }}.conf"
      - "{{ node_custom_config }}/nova/{{ nova_cell_ceph_backend['cluster'] }}.conf"
  template:
    src: "{{ lookup('first_found', paths) }}"
    dest: "{{ node_config_directory }}/{{ item }}/"
    owner: "{{ config_owner_user }}"
    group: "{{ config_owner_group }}"
    mode: "0660"
  become: true
  with_items:
    - nova-compute
    - nova-libvirt
  when:
    - service | service_enabled_and_mapped_to_host
    - nova_backend == "rbd"

- when:
    - not enable_nova_libvirt_container | bool
    - inventory_hostname in groups[nova_cell_compute_group]
    - nova_backend == "rbd"
  block:
    - name: Ensure /etc/ceph directory exists (host libvirt)
      vars:
        paths:
          - "{{ node_custom_config }}/nova/{{ inventory_hostname }}/{{ nova_cell_ceph_backend['cluster'] }}.conf"
          - "{{ node_custom_config }}/nova/{{ nova_cell_ceph_backend['cluster'] }}.conf"
      file:
        path: "/etc/ceph/"
        state: "directory"
        owner: "root"
        group: "root"
        mode: "0755"
      become: true

    - name: Copy over ceph.conf (host libvirt)
      vars:
        paths:
          - "{{ node_custom_config }}/nova/{{ inventory_hostname }}/{{ nova_cell_ceph_backend['cluster'] }}.conf"
          - "{{ node_custom_config }}/nova/{{ nova_cell_ceph_backend['cluster'] }}.conf"
      template:
        src: "{{ lookup('first_found', paths) }}"
        dest: "/etc/ceph/{{ nova_cell_ceph_backend['cluster'] }}.conf"
        owner: "root"
        group: "root"
        mode: "0644"
      become: true

- vars:
    libvirt_secrets_dir: >-
      {{ (node_config_directory ~ '/nova-libvirt/secrets')
         if enable_nova_libvirt_container | bool
         else '/etc/libvirt/secrets' }}
    # NOTE(mgoddard): When running libvirt as a host daemon, on CentOS it
    # appears to pick up secrets automatically, while on Ubuntu it requires a
    # reload. This may be due to differences in tested versions of libvirt
    # (8.0.0 vs 6.0.0). Reload should be low overhead, so do it always.
    libvirt_restart_handlers: >-
      {{ ['Reload libvirtd']
         if not enable_nova_libvirt_container | bool else
         [] }}
  block:
    - name: Ensuring libvirt secrets directory exists
      vars:
        service: "{{ nova_cell_services['nova-libvirt'] }}"
      file:
        path: "{{ libvirt_secrets_dir }}"
        state: "directory"
        owner: "{{ config_owner_user }}"
        group: "{{ config_owner_group }}"
        mode: "0770"
      become: true
      when: service | service_enabled_and_mapped_to_host

    - name: Pushing nova secret xml for libvirt
      vars:
        service: "{{ nova_cell_services['nova-libvirt'] }}"
      template:
        src: "secret.xml.j2"
        dest: "{{ libvirt_secrets_dir }}/{{ item.uuid }}.xml"
        owner: "{{ config_owner_user }}"
        group: "{{ config_owner_group }}"
        mode: "0600"
      become: true
      when:
        - service | service_enabled_and_mapped_to_host
        - item.enabled | bool
      with_items:
        - uuid: "{{ rbd_secret_uuid }}"
          name: "ceph-ephemeral-nova"
          desc: "Ceph Client Secret for Ephemeral Storage (Nova)"
          enabled: "{{ nova_backend == 'rbd' }}"
        - uuid: "{{ cinder_rbd_secret_uuid }}"
          name: "ceph-persistent-cinder"
          desc: "Ceph Client Secret for Persistent Storage (Cinder)"
          enabled: "{{ cinder_backend_ceph }}"
      notify: "{{ libvirt_restart_handlers }}"

    - name: Pushing secrets key for libvirt
      vars:
        service: "{{ nova_cell_services['nova-libvirt'] }}"
      template:
        src: "libvirt-secret.j2"
        dest: "{{ libvirt_secrets_dir }}/{{ item.uuid }}.base64"
        owner: "{{ config_owner_user }}"
        group: "{{ config_owner_group }}"
        mode: "0600"
      become: true
      when:
        - service | service_enabled_and_mapped_to_host
        - item.enabled | bool
        - external_ceph_cephx_enabled | bool
      with_items:
        # NOTE(yoctozepto): 'default' filter required due to eager evaluation of item content
        # which will be undefined if the applicable condition is False
        - uuid: "{{ rbd_secret_uuid }}"
          result: "{{ nova_cephx_raw_key | default }}"
          enabled: "{{ nova_backend == 'rbd' }}"
        - uuid: "{{ cinder_rbd_secret_uuid }}"
          result: "{{ cinder_cephx_raw_key | default }}"
          enabled: "{{ cinder_backend_ceph }}"
      notify: "{{ libvirt_restart_handlers }}"
      no_log: True