1
0
IaC/ansible/roles/k8s_storage_deploy/tasks/main.yaml

91 lines
3.0 KiB
YAML
Raw Normal View History

2022-11-02 05:18:55 -04:00
---
- name: create target directory for rook files
ansible.builtin.file:
path: "{{ ansible_search_path[0] }}/files/rook"
state: directory
mode: 0775
- name: load rbd kernel module
become: true
delegate_to: "{{ item }}"
with_items: "{{ groups['k8s_worker'] }}"
community.general.modprobe:
name: rbd
state: present
- name: set rbd kernel module to load at boot
become: true
delegate_to: "{{ item }}"
with_items: "{{ groups['k8s_worker'] }}"
ansible.builtin.copy:
dest: /etc/modules-load.d/rbd.conf
content: rbd
owner: root
group: root
mode: 0660
- name: install lvm2 package
become: true
delegate_to: "{{ item }}"
with_items: "{{ groups['k8s_worker'] }}"
community.general.pacman:
name: lvm2
state: latest
update_cache: true
- name: download the rook manifests
ansible.builtin.uri:
url: https://raw.githubusercontent.com/rook/rook/{{ rook_version }}/deploy/examples/{{ item }}.yaml
dest: "{{ ansible_search_path[0] }}/files/rook/rook_{{ item }}_{{ rook_version }}.yaml"
creates: "{{ ansible_search_path[0] }}/files/rook/rook_{{ item }}_{{ rook_version }}.yaml"
mode: 0664
with_items:
- crds
- common
- operator
- cluster
- name: deploy the rook manifest # The order of the items is important, crds > common > operator , see https://github.com/rook/rook/blob/v1.10.4/deploy/examples/common.yaml
kubernetes.core.k8s:
src: "{{ ansible_search_path[0] }}/files/rook/rook_{{ item }}_{{ rook_version }}.yaml"
state: present
with_items:
- crds
- common
- operator
# TODO somehow turn this command:
# kubectl -n rook-ceph get pod -o json | jq '.items[].status.containerStatuses[].ready'
# into a gate, not proceeding until it returns true, and timing out at some limit, ~2m
- name: read the default rook cluster config into memory
ansible.builtin.slurp:
src: "{{ ansible_search_path[0] }}/files/rook/rook_cluster_{{ rook_version }}.yaml"
register: rook_file_raw
- name: parse rook cluster settings from the file data
ansible.builtin.set_fact:
rook_default_cluster: "{{ rook_file_raw['content'] | b64decode | from_yaml }}"
- name: update the rook cluster settings with desired changes
ansible.utils.update_fact:
updates:
- path: rook_default_cluster.spec.storage.useAllDevices
value: "{{ k8s_storage_all_devices }}"
- path: rook_default_cluster.spec.storage.deviceFilter
value: "{{ k8s_storage_device_filter }}"
register: rook_updated_cluster
- name: debug the updated rook cluster settings
ansible.builtin.debug:
var: rook_updated_cluster.rook_default_cluster
- name: write the updated rook cluster settings out to file
ansible.builtin.copy:
content: "{{ rook_updated_cluster.rook_default_cluster | to_nice_yaml }}"
dest: "{{ ansible_search_path[0] }}/files/rook/rook_cluster_modified.yaml"
- name: apply the rook cluster manifest
kubernetes.core.k8s:
src: "{{ ansible_search_path[0] }}/files/rook/rook_cluster_modified.yaml"
state: present