role_setup_volume/tasks/main.yml
2024-10-19 21:49:05 +02:00

68 lines
2.1 KiB
YAML

---
- name: Create /mnt/volumes/{{ volume.name }} directory
ansible.builtin.file:
path: "/mnt/volumes/{{ volume.name }}"
state: directory
mode: '0755'
become: true
- name: Create {{ volume.name }} volume
openstack.cloud.volume:
state: present
size: "{{ volume.size }}"
volume_type: "{{ volume.vol_type }}"
name: "{{ target_name.split('.')[0] }}-{{ volume.name }}"
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 }}"
- name: Attach {{ volume.name }} volume to instance
openstack.cloud.server_volume:
state: present
server: "{{ target_name }}"
volume: "{{ target_name.split('.')[0] }}-{{ volume.name }}"
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
- name: Create a ext4 filesystem on {{ volume.name }} volume
community.general.filesystem:
fstype: ext4
dev: "{{ volume_output.attachments[0].device }}"
register: mkfs
become: true
- debug: var=mkfs
- ansible.builtin.meta: end_host
- name: mount /mnt/volumes/{{ volume.name }}
ansible.posix.mount:
path: "/mnt/volumes/{{ volume.name }}"
src: "{{ volume_output.attachments[0].device }}"
fstype: ext4
state: mounted
become: true
- name: Create /mnt/volumes/{{ volume.name }}/data directory
ansible.builtin.file:
path: "/mnt/volumes/{{ volume.name }}/data"
state: directory
mode: '0755'
become: true