2024-03-22 13:54:36 +00:00
|
|
|
---
|
2024-03-22 14:08:04 +00:00
|
|
|
- name: Create /mnt/volumes/{{ volume.name }} directory
|
2024-03-22 13:54:36 +00:00
|
|
|
ansible.builtin.file:
|
2024-03-22 14:08:04 +00:00
|
|
|
path: "/mnt/volumes/{{ volume.name }}"
|
2024-03-22 13:54:36 +00:00
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
become: true
|
|
|
|
|
2024-03-22 14:08:04 +00:00
|
|
|
- name: Create {{ volume.name }} volume
|
2024-03-22 13:54:36 +00:00
|
|
|
openstack.cloud.volume:
|
|
|
|
state: present
|
2024-03-22 14:08:04 +00:00
|
|
|
size: "{{ volume.size }}"
|
|
|
|
volume_type: "{{ volume.vol_type }}"
|
|
|
|
name: "{{ target_name.split('.')[0] }}-{{ volume.name }}"
|
2024-03-22 13:54:36 +00:00
|
|
|
environment:
|
|
|
|
OS_AUTH_URL: "{{ OS_AUTH_URL }}"
|
|
|
|
OS_IDENTITY_API_VERSION: "{{ OS_IDENTITY_API_VERSION }}"
|
|
|
|
OS_USER_DOMAIN_NAME: "{{ OS_USER_DOMAIN_NAME }}"
|
|
|
|
OS_PROJECT_DOMAIN_NAME: "{{ OS_PROJECT_DOMAIN_NAME }}"
|
|
|
|
OS_TENANT_ID: "{{ OS_TENANT_ID }}"
|
|
|
|
OS_TENANT_NAME: "{{ OS_TENANT_NAME }}"
|
|
|
|
OS_USERNAME: "{{ OS_USERNAME }}"
|
|
|
|
OS_PASSWORD: "{{ OS_PASSWORD }}"
|
|
|
|
OS_REGION_NAME: "{{ OS_REGION_NAME }}"
|
|
|
|
|
2024-03-22 14:08:04 +00:00
|
|
|
- name: Attach {{ volume.name }} volume to instance
|
2024-03-22 13:54:36 +00:00
|
|
|
openstack.cloud.server_volume:
|
|
|
|
state: present
|
|
|
|
server: "{{ target_name }}"
|
2024-03-22 14:08:04 +00:00
|
|
|
volume: "{{ target_name.split('.')[0] }}-{{ volume.name }}"
|
2024-03-22 13:54:36 +00:00
|
|
|
environment:
|
|
|
|
OS_AUTH_URL: "{{ OS_AUTH_URL }}"
|
|
|
|
OS_IDENTITY_API_VERSION: "{{ OS_IDENTITY_API_VERSION }}"
|
|
|
|
OS_USER_DOMAIN_NAME: "{{ OS_USER_DOMAIN_NAME }}"
|
|
|
|
OS_PROJECT_DOMAIN_NAME: "{{ OS_PROJECT_DOMAIN_NAME }}"
|
|
|
|
OS_TENANT_ID: "{{ OS_TENANT_ID }}"
|
|
|
|
OS_TENANT_NAME: "{{ OS_TENANT_NAME }}"
|
|
|
|
OS_USERNAME: "{{ OS_USERNAME }}"
|
|
|
|
OS_PASSWORD: "{{ OS_PASSWORD }}"
|
|
|
|
OS_REGION_NAME: "{{ OS_REGION_NAME }}"
|
|
|
|
register: volume_output
|
|
|
|
|
2024-03-22 14:08:04 +00:00
|
|
|
- name: Create a ext4 filesystem on {{ volume.name }} volume
|
2024-03-22 13:54:36 +00:00
|
|
|
community.general.filesystem:
|
|
|
|
fstype: ext4
|
|
|
|
dev: "{{ volume_output.attachments[0].device }}"
|
2024-10-19 19:49:05 +00:00
|
|
|
register: mkfs
|
2024-03-22 13:54:36 +00:00
|
|
|
become: true
|
|
|
|
|
2024-10-19 19:49:05 +00:00
|
|
|
- debug: var=mkfs
|
|
|
|
- ansible.builtin.meta: end_host
|
|
|
|
|
2024-03-22 14:08:04 +00:00
|
|
|
- name: mount /mnt/volumes/{{ volume.name }}
|
2024-03-22 13:54:36 +00:00
|
|
|
ansible.posix.mount:
|
2024-03-22 14:08:04 +00:00
|
|
|
path: "/mnt/volumes/{{ volume.name }}"
|
2024-03-22 13:54:36 +00:00
|
|
|
src: "{{ volume_output.attachments[0].device }}"
|
|
|
|
fstype: ext4
|
|
|
|
state: mounted
|
|
|
|
become: true
|
|
|
|
|
2024-03-22 14:08:04 +00:00
|
|
|
- name: Create /mnt/volumes/{{ volume.name }}/data directory
|
2024-03-22 13:54:36 +00:00
|
|
|
ansible.builtin.file:
|
2024-03-22 14:08:04 +00:00
|
|
|
path: "/mnt/volumes/{{ volume.name }}/data"
|
2024-03-22 13:54:36 +00:00
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
become: true
|
|
|
|
|