ansible-hashistack/roles/nomad/tasks/csi_volumes.yml
2023-09-25 13:55:32 +02:00

40 lines
1.2 KiB
YAML

---
- name: Check if volume has already been created and registered
ansible.builtin.uri:
url: "http://nomad.service.consul:4646/v1/volume/csi/{{ item.id }}"
method: GET
remote_src: yes
register: volume_exists
ignore_errors: true
- name: Check for state of CSI Plugins to prevent race
block:
- name: Check controller plugin
ansible.builtin.uri:
url: "http://nomad.service.consul:4646/v1/job/plugin-nfs-controller"
method: GET
remote_src: yes
register: controller_status
until: controller_status | json_query('json.Status') == 'running'
- name: Check node plugin
ansible.builtin.uri:
url: "http://nomad.service.consul:4646/v1/job/plugin-nfs-node"
method: GET
remote_src: yes
register: node_status
until: node_status | json_query('json.Status') == 'running'
- name: Create CSI volume with Nomad API
ansible.builtin.uri:
url: http://nomad.service.consul:4646/v1/volume/csi/{{ item.id }}/create
method: PUT
body_format: json
body: "{{ lookup('template', 'csi-volumes.json.j2') }}"
remote_src: yes
register: csi_volume
until: csi_volume.status == 200
retries: 5
delay: 10
when: volume_exists.status == 404