lae / ansible-role-proxmox

IaC for Proxmox VE clusters.
MIT License
468 stars 139 forks source link

Specifying pve_storage per node in a cluster #196

Closed Mohitsharma44 closed 1 year ago

Mohitsharma44 commented 1 year ago

Hey team,

Thanks for the fantastic ansible role. I have a use case where I want to create pve_storages of type dir at different path for each node in a cluster.

The following layout may explain what Im trying to do better.

inventory/ hypervisors.ini

[hypervisors:children]
pve01
pve02
pve03

group_vars/ all.yml:

pve_group: hypervisors
pve_cluster_clustername: phoenixDC

pve_manage_ssh: true
pve_cluster_enabled: true
pve_manage_hosts_enabled: true

host_vars/ pve03/all.yml:

pve_storages:
  - name: 4tbdata-vmdata
    type: dir
    path: /vmdata
    maxfiles: 60 # Max number of backup files per VM
    content: ["images", "iso", "backup", "snippets", "vztmpl"]

Now the playbook run shows the Configure Proxmox Storage task gets skipped.

Sample output:

...
...

TASK [lae.proxmox : Configure Proxmox Storage] *****************************************************************************************************************************************
Wednesday 27 July 2022  21:24:44 -0700 (0:00:00.205)       0:02:05.256 ********
skipping: [pve03.sharmamohit.com] => (item={'name': '4tbdata-vmdata', 'type': 'dir', 'path': '/vmdata', 'maxfiles': 60, 'content': ['images', 'iso', 'backup', 'snippets', 'vztmpl']})
...
...

It seems like this line of code: https://github.com/lae/ansible-role-proxmox/blob/e2c6015c002aeb27dbe3ea700c75ef6cd6a87a67/tasks/main.yml#L290 restricts any storage operation only to the first node in the pve_group. I'm trying to understand the reason behind it.

I believe the when condition could instead be:

when: "not pve_cluster_enabled | bool or (pve_cluster_enabled | bool and inventory_hostname in groups[pve_group])"

(I'm not sure how this would affect other storage types though..)

lae commented 1 year ago

It's restricted to executing on the first node in pve_group because, if I recall correctly, configuring storage is a cluster-wide operation and not doing so introduces race conditions.

I believe what you want to do is set nodes in the pve_storages variable to that particular node. In other words:

group_vars/all.yml:

pve_group: hypervisors
pve_cluster_clustername: phoenixDC

pve_manage_ssh: true
pve_cluster_enabled: true
pve_manage_hosts_enabled: true

pve_storages:
  - name: 4tbdata-vmdata
    type: dir
    path: /vmdata
    maxfiles: 60 # Max number of backup files per VM
    content: ["images", "iso", "backup", "snippets", "vztmpl"]
    nodes: ["pve03"]

Does that work for you?

Mohitsharma44 commented 1 year ago

Yep.. that works. RTFM! And yeah, you're right, configuring storage is a cluster-wide operation.

Thanks alot!