data structure in inventory (i use AWX) so just look at os_directory_file_items and mount_list
___
- name: kubernetes workers
inventory: inventory1
description:
state: present
children:
- childnodes
variables:
os_directory_file_items:
- name: mnt
path: /mnt
state: directory
- name: plceholder1
path: /mnt/placeholder
state: directory
- name: Placeholder2
path: /mnt/Placeholder2
state: directory
mount_list:
- path: '/mnt/placeholder'
mnt_name: Placeholder1
src: 'Server1:/volume1//Placeholder1'
fstype: nfs
state: mounted
- path: /mnt/Placeholder2
mnt_name: Placeholder2
src: 'Server1:/volume1//Placeholder2'
fstype: nfs
state: mounted
___
main.yml in role
---
- name: Create Mountpoint on OS
mount:
path: "{{ mount_item.path }}"
fstab: "{{ mount_item.fstab | default(omit)}}"
boot: "{{ mount_item.boot | default(omit)}}"
dump: "{{ mount_item.dump | default(0)}}"
fstype: "{{ mount_item.fstype | default(0)}}"
opts: "{{ mount_item.opts | default(omit)}}"
passno: "{{ mount_item.passno | default(0)}}"
src: "{{ mount_item.src | default('present')}}"
state: "{{ mount_item.state | default('mounted')}}"
loop: "{{ mount_list }}"
loop_control:
loop_var: mount_item
when: mount_list is defined
___
playbook
---
- name: Configure common linux settings
hosts: all
roles:
- { role: configure_common_os_directory , when: os_directory_file_items is defined , tags: os_directory_file_settings }
- { role: configure_mnt , when: mount_list is defined , tags: linux_mnt_settings }