Skip to content

Commit

Permalink
ansible: Add lvmcluster logic
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Jun 17, 2024
1 parent 0d6ee5e commit b0e124b
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
- `cluster`
- `ui`: Whether to serve the Incus UI

## LVM cluster
- `lvmcluster_name`: Name identifier for the deployment (**required**, type: string)
- `lvmcluster_vgs`: Dict of VG name to storage device path

## OVN

- `ovn_ip_address`: Override for the server's IP address (used for tunnels and DB traffic) (type: string)
Expand Down
89 changes: 89 additions & 0 deletions ansible/books/lvmcluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
- name: LVM Cluster - Generate configuration
hosts: all
order: shuffle
gather_facts: no
vars:
task_name: "{{ lvmcluster_name | default('') }}"
any_errors_fatal: true
tasks:
- name: Create cluster directory
delegate_to: 127.0.0.1
file:
path: "../data/lvmcluster/{{ task_name }}"
mode: 0755
state: directory
throttle: 1
when: 'task_name'
register: create

- name: Create cluster host_id tracking
delegate_to: 127.0.0.1
throttle: 1
copy:
content: "{}"
dest: "../data/lvmcluster/{{ task_name }}/host_id.yaml"
mode: 0644
when: "create.changed"

- name: Update cluster host_id tracking
delegate_to: 127.0.0.1
throttle: 1
template:
src: "../files/lvmcluster/host_id.yaml.tpl"
dest: "../data/lvmcluster/{{ task_name }}/host_id.yaml"
vars:
task_host_ids: "{{ lookup('file', '../data/lvmcluster/' + task_name + '/host_id.yaml') | from_yaml }}"

- name: LVM Cluster - Install packages and host config
hosts: all
order: shuffle
gather_facts: no
vars:
task_name: "{{ lvmcluster_name | default('') }}"
task_host_ids: "{{ lookup('file', '../data/lvmcluster/' + task_name + '/host_id.yaml') | from_yaml }}"
any_errors_fatal: true
tasks:
- name: Install the LVM packages
apt:
name:
- lvm2
- lvm2-lockd
- sanlock
install_recommends: no
state: present

- name: Configure for LVM cluster
template:
src: ../files/lvmcluster/lvmlocal.conf.tpl
dest: /etc/lvm/lvmlocal.conf

- name: LVM Cluster - Create VGs
hosts: all
order: shuffle
gather_facts: no
vars:
task_vgs: "{{ lvmcluster_vgs | default({}) }}"
any_errors_fatal: true
tasks:
- name: Check for existing VGs
shell:
cmd: "vgs {{ item }}"
register: check
loop: "{{ lvmcluster_vgs.keys() }}"
run_once: true
changed_when: false
failed_when: "check.rc not in (0, 5)"

- name: Create the VG (first server)
shell:
cmd: "vgcreate --shared {{ item.item }} {{ task_vgs[item.item] }}"
when: "item.rc == 5"
loop: "{{ check.results }}"
run_once: true
register: create

- name: Ensure lock manager is running
shell:
cmd: "vgchange --lock-start"
when: "create.changed"
Empty file.
1 change: 1 addition & 0 deletions ansible/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- import_playbook: books/ceph.yaml
- import_playbook: books/lvmcluster.yaml
- import_playbook: books/ovn.yaml
- import_playbook: books/incus.yaml
15 changes: 15 additions & 0 deletions ansible/files/lvmcluster/host_id.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% set ns = namespace() %}
{% set ns.next = 1 %}
{% for key, value in task_host_ids.items() %}
{% if value >= ns.next %}
{% set ns.next = value + 1 %}
{% endif %}
{% endfor %}
{% for host in vars['ansible_play_hosts'] %}
{% if not host in task_host_ids %}
{{ host }}: {{ ns.next }}
{% set ns.next = ns.next + 1 %}
{% else %}
{{ host }}: {{ task_host_ids[host] | default(0) }}
{% endif %}
{% endfor %}
11 changes: 11 additions & 0 deletions ansible/files/lvmcluster/lvmlocal.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Managed by Ansible, do not modify.

# Cluster is {{ task_name }}

global {
use_lvmlockd = 1
}

local {
host_id = {{ task_host_ids[inventory_hostname] }}
}

0 comments on commit b0e124b

Please sign in to comment.