|
1 | 1 | # This is an Ansible version of what "pveceph install" actually does
|
2 |
| -- name: Configure Ceph package source |
3 |
| - apt_repository: |
4 |
| - repo: '{{ pve_ceph_repository_line }}' |
5 |
| - filename: ceph.list |
6 |
| - state: present |
7 |
| - |
8 |
| -- name: Install Ceph packages |
9 |
| - apt: |
10 |
| - name: |
11 |
| - - ceph |
12 |
| - - ceph-common |
13 |
| - - ceph-mds |
14 |
| - - ceph-fuse |
15 |
| - - gdisk |
16 |
| - install_recommends: false |
17 |
| - |
18 | 2 | - name: Install custom Ceph systemd service
|
19 | 3 | copy:
|
20 | 4 | src: /usr/share/doc/pve-manager/examples/ceph.service
|
|
34 | 18 | when:
|
35 | 19 | - "ansible_distribution_release == 'stretch'"
|
36 | 20 |
|
37 |
| -- name: Create initial Ceph config |
38 |
| - command: 'pveceph init --network {{ pve_ceph_network }}' |
39 |
| - args: |
40 |
| - creates: /etc/ceph/ceph.conf |
41 |
| - when: inventory_hostname == groups[pve_ceph_mon_group][0] |
| 21 | +- block: |
| 22 | + - name: Create initial Ceph config |
| 23 | + command: 'pveceph init --network {{ pve_ceph_network }}' |
| 24 | + args: |
| 25 | + creates: /etc/ceph/ceph.conf |
42 | 26 |
|
43 |
| -- name: Create initial Ceph monitor |
44 |
| - command: 'pveceph mon create' |
45 |
| - args: |
46 |
| - creates: '/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/' |
47 |
| - register: _ceph_initial_mon |
48 |
| - when: inventory_hostname == groups[pve_ceph_mon_group][0] |
| 27 | + - name: Create initial Ceph monitor |
| 28 | + command: 'pveceph mon create' |
| 29 | + args: |
| 30 | + creates: '/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/' |
| 31 | + register: _ceph_initial_mon |
49 | 32 |
|
50 |
| -- name: Fail if initial monitor creation failed |
51 |
| - fail: |
52 |
| - msg: 'Ceph intial monitor creation failed.' |
53 |
| - when: hostvars[groups[pve_ceph_mon_group][0]]._ceph_initial_mon is failed |
| 33 | + - name: Fail if initial monitor creation failed |
| 34 | + fail: |
| 35 | + msg: 'Ceph intial monitor creation failed.' |
| 36 | + when: _ceph_initial_mon is failed |
| 37 | + |
| 38 | + when: inventory_hostname == groups[pve_ceph_mon_group][0] |
54 | 39 |
|
55 | 40 | - name: Create additional Ceph monitors
|
56 | 41 | command: 'pveceph mon create'
|
57 | 42 | args:
|
58 | 43 | creates: '/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/'
|
59 |
| - when: not inventory_hostname == groups[pve_ceph_mon_group][0] |
| 44 | + when: inventory_hostname != groups[pve_ceph_mon_group][0] |
60 | 45 |
|
61 | 46 | - name: Create Ceph OSDs
|
62 | 47 | command: >-
|
63 | 48 | pveceph osd create {{ item.device }}
|
64 |
| - {{ ("block.db" in item) | ternary("--journal_dev", "") }} {{ item["block.db"] | default("") }} |
| 49 | + {% if "block.db" in item %}--journal_dev {{ item["block.db"] }}{% endif %} |
65 | 50 | args:
|
66 | 51 | creates: '{{ item.device }}1'
|
67 | 52 | with_items: '{{ pve_ceph_osds }}'
|
68 | 53 |
|
69 |
| -- name: List Ceph CRUSH rules |
70 |
| - command: 'ceph osd crush rule ls' |
71 |
| - changed_when: false |
72 |
| - register: ceph_crush |
73 |
| - when: inventory_hostname == groups[pve_ceph_mon_group][0] |
| 54 | +- block: |
| 55 | + - name: List Ceph CRUSH rules |
| 56 | + command: 'ceph osd crush rule ls' |
| 57 | + changed_when: false |
| 58 | + register: _ceph_crush |
| 59 | + |
| 60 | + - name: Create Ceph CRUSH rules |
| 61 | + command: >- |
| 62 | + ceph osd crush rule create-replicated |
| 63 | + {{ item.name }} default host {{ item.class | default("") }} |
| 64 | + when: item.name not in _ceph_crush.stdout_lines |
| 65 | + with_items: '{{ pve_ceph_crush_rules }}' |
| 66 | + |
| 67 | + - name: List Ceph Pools |
| 68 | + command: ceph osd pool ls |
| 69 | + changed_when: false |
| 70 | + register: _ceph_pools |
| 71 | + |
| 72 | + - name: Create Ceph Pools |
| 73 | + command: >- |
| 74 | + pveceph pool create {{ item.name }} |
| 75 | + {% if 'storage' in item %} |
| 76 | + --add_storages {{ item.storage }} |
| 77 | + {% endif %} |
| 78 | + {% if 'application' in item %} |
| 79 | + --application {{ item.application }} |
| 80 | + {% endif %} |
| 81 | + {% if 'rule' in item %} |
| 82 | + --crush_rule {{ item.rule }} |
| 83 | + {% endif %} |
| 84 | + {% if 'pgs' in item %} |
| 85 | + --pg_num {{ item.pgs }} |
| 86 | + {% endif %} |
| 87 | + when: item.name not in _ceph_pools.stdout_lines |
| 88 | + with_items: '{{ pve_ceph_pools }}' |
74 | 89 |
|
75 |
| -- name: Create Ceph CRUSH rules |
76 |
| - command: >- |
77 |
| - ceph osd crush rule create-replicated |
78 |
| - {{ item.name }} default host {{ item.class | default("") }} |
79 |
| - when: |
80 |
| - - inventory_hostname == groups[pve_ceph_mon_group][0] |
81 |
| - - item.name not in ceph_crush.stdout_lines |
82 |
| - with_items: '{{ pve_ceph_crush_rules }}' |
83 |
| - |
84 |
| -- name: List Ceph Pools |
85 |
| - command: ceph osd pool ls |
86 |
| - changed_when: false |
87 |
| - register: ceph_pools |
88 | 90 | when: inventory_hostname == groups[pve_ceph_mon_group][0]
|
89 | 91 |
|
90 |
| -- name: Create Ceph Pools |
91 |
| - command: >- |
92 |
| - pveceph pool create {{ item.name }} |
93 |
| - {% if 'storage' in item %} |
94 |
| - --add_storages {{ item.storage }} |
95 |
| - {% endif %} |
96 |
| - {% if 'application' in item %} |
97 |
| - --application {{ item.application }} |
98 |
| - {% endif %} |
99 |
| - {% if 'rule' in item %} |
100 |
| - --crush_rule {{ item.rule }} |
101 |
| - {% endif %} |
102 |
| - {% if 'pgs' in item %} |
103 |
| - --pg_num {{ item.pgs }} |
104 |
| - {% endif %} |
105 |
| - when: |
106 |
| - - inventory_hostname == groups[pve_ceph_mon_group][0] |
107 |
| - - item.name not in ceph_pools.stdout_lines |
108 |
| - with_items: '{{ pve_ceph_pools }}' |
109 |
| - |
110 | 92 | - name: Create Ceph MDS servers
|
111 | 93 | command: pveceph mds create
|
112 | 94 | args:
|
|
122 | 104 | delay: 2
|
123 | 105 | when: _ceph_mds_create is changed
|
124 | 106 |
|
125 |
| -- name: List Ceph Filesystems |
126 |
| - command: ceph fs ls -f json |
127 |
| - changed_when: false |
128 |
| - when: |
129 |
| - - inventory_hostname == groups[pve_ceph_mon_group][0] |
130 |
| - - pve_ceph_fs | length > 0 |
131 |
| - register: ceph_fs |
132 |
| - |
133 |
| -- name: Create Ceph Filesystems |
134 |
| - command: >- |
135 |
| - pveceph fs create |
136 |
| - --name {{ item.name }} |
137 |
| - --add-storage {{ item.storage }} |
138 |
| - --pg_num {{ item.pgs }} |
139 |
| - register: ceph_fs_create |
140 |
| - failed_when: ceph_fs_create.stderr |
141 |
| - when: |
142 |
| - - inventory_hostname == groups[pve_ceph_mon_group][0] |
143 |
| - - item.name not in (ceph_fs.stdout | from_json | map(attribute="name")) |
144 |
| - with_items: '{{ pve_ceph_fs }}' |
145 |
| - |
146 |
| -- name: Get Ceph Filesystem pool CRUSH rules |
147 |
| - command: 'ceph -f json osd pool get {{ item.0.name }}_{{ item.1 }} crush_rule' |
148 |
| - changed_when: false |
149 |
| - when: |
150 |
| - - inventory_hostname == groups[pve_ceph_mon_group][0] |
151 |
| - - pve_ceph_fs | length > 0 |
152 |
| - register: ceph_fs_rule |
153 |
| - loop: '{{ pve_ceph_fs | product(["data", "metadata"]) | list }}' |
154 |
| - |
155 |
| -- name: Set Ceph Filesystem pool CRUSH rules |
156 |
| - command: >- |
157 |
| - ceph osd pool set {{ item.item.0.name }}_{{ item.item.1 }} crush_rule {{ item.item.0.rule }} |
158 |
| - when: |
159 |
| - - inventory_hostname == groups[pve_ceph_mon_group][0] |
160 |
| - - item.item.0.rule != (item.stdout | from_json).crush_rule |
161 |
| - loop: '{{ ceph_fs_rule.results }}' |
162 |
| - loop_control: |
163 |
| - label: '{{ item.item.0.name }}_{{ item.item.1 }}' |
164 |
| - |
165 |
| -- name: Create Ceph filesystem key |
166 |
| - command: 'ceph auth get-or-create client.{{ item.name }} osd "allow rw pool={{ item.name }}_data" mon "allow r" mds "allow rw"' |
167 |
| - register: ceph_fs_auth |
168 |
| - changed_when: '"added key" in ceph_fs_auth.stdout' |
169 |
| - when: |
170 |
| - - inventory_hostname == groups[pve_ceph_mon_group][0] |
171 |
| - - item.mountpoint is defined |
172 |
| - loop: '{{ pve_ceph_fs }}' |
| 107 | +- block: |
| 108 | + - name: List Ceph Filesystems |
| 109 | + command: ceph fs ls -f json |
| 110 | + changed_when: false |
| 111 | + when: pve_ceph_fs | length > 0 |
| 112 | + register: _ceph_fs |
| 113 | + |
| 114 | + - name: Create Ceph Filesystems |
| 115 | + command: >- |
| 116 | + pveceph fs create |
| 117 | + --name {{ item.name }} |
| 118 | + --add-storage {{ item.storage }} |
| 119 | + --pg_num {{ item.pgs }} |
| 120 | + register: _ceph_fs_create |
| 121 | + failed_when: _ceph_fs_create.stderr |
| 122 | + when: item.name not in (_ceph_fs.stdout | from_json | map(attribute="name")) |
| 123 | + with_items: '{{ pve_ceph_fs }}' |
| 124 | + |
| 125 | + - name: Get Ceph Filesystem pool CRUSH rules |
| 126 | + command: 'ceph -f json osd pool get {{ item.0.name }}_{{ item.1 }} crush_rule' |
| 127 | + changed_when: false |
| 128 | + when: pve_ceph_fs | length > 0 |
| 129 | + register: _ceph_fs_rule |
| 130 | + loop: '{{ pve_ceph_fs | product(["data", "metadata"]) | list }}' |
| 131 | + |
| 132 | + - name: Set Ceph Filesystem pool CRUSH rules |
| 133 | + command: >- |
| 134 | + ceph osd pool set {{ item.item.0.name }}_{{ item.item.1 }} crush_rule {{ item.item.0.rule }} |
| 135 | + when: item.item.0.rule != (item.stdout | from_json).crush_rule |
| 136 | + loop: '{{ _ceph_fs_rule.results }}' |
| 137 | + loop_control: |
| 138 | + label: '{{ item.item.0.name }}_{{ item.item.1 }}' |
| 139 | + |
| 140 | + - name: Create Ceph filesystem key |
| 141 | + command: 'ceph auth get-or-create client.{{ item.name }} osd "allow rw pool={{ item.name }}_data" mon "allow r" mds "allow rw"' |
| 142 | + register: _ceph_fs_auth |
| 143 | + changed_when: '"added key" in _ceph_fs_auth.stdout' |
| 144 | + when: item.mountpoint is defined |
| 145 | + loop: '{{ pve_ceph_fs }}' |
| 146 | + when: inventory_hostname == groups[pve_ceph_mon_group][0] |
173 | 147 |
|
174 | 148 | - name: Fetch Ceph filesystem key
|
175 | 149 | command: 'ceph auth print-key client.{{ item.name }}'
|
176 | 150 | args:
|
177 | 151 | creates: '/etc/ceph/{{ item.name }}.secret'
|
178 |
| - register: ceph_fs_key |
| 152 | + register: _ceph_fs_key |
179 | 153 | when: item.mountpoint is defined
|
180 | 154 | loop: '{{ pve_ceph_fs }}'
|
181 | 155 |
|
|
187 | 161 | mode: '0600'
|
188 | 162 | content: '{{ item.stdout }}'
|
189 | 163 | when: item is changed
|
190 |
| - loop: '{{ ceph_fs_key.results }}' |
| 164 | + loop: '{{ _ceph_fs_key.results }}' |
191 | 165 | loop_control:
|
192 | 166 | label: '{{ item.item }}'
|
193 | 167 |
|
|
0 commit comments