I want to have loop for mount filesystems.
For this moment I’m thinking about this kind of implementation:
I have 2 files :
# #filesystem.yml
<code>---
filesystems:
lif: "{{ lif_ip1 }}"
mountpoint: "{{ mountpoint1 }}"
mount: "{{ mount1 }}"
lif: "{{ lif_ip2 }}"
mountpoint: "{{ mountpoint2 }}"
mount: "{{ mount2 }}"
include_tasks: "mount_dirs.yml"
loop: "{{ filesystems }}"
</code>
<code>---
filesystems:
lif: "{{ lif_ip1 }}"
mountpoint: "{{ mountpoint1 }}"
mount: "{{ mount1 }}"
lif: "{{ lif_ip2 }}"
mountpoint: "{{ mountpoint2 }}"
mount: "{{ mount2 }}"
include_tasks: "mount_dirs.yml"
loop: "{{ filesystems }}"
</code>
---
filesystems:
lif: "{{ lif_ip1 }}"
mountpoint: "{{ mountpoint1 }}"
mount: "{{ mount1 }}"
lif: "{{ lif_ip2 }}"
mountpoint: "{{ mountpoint2 }}"
mount: "{{ mount2 }}"
include_tasks: "mount_dirs.yml"
loop: "{{ filesystems }}"
# #mount_dirs.yml
<code>---
name: mount filesystems
ansible.posix.mount:
fstype: nfs
opts: "{{ mount_options }}"
src: "{{ lif }}:{{ mount }}"
path: "{{ mountpoint }}"
state: ephemeral
become: yes
</code>
<code>---
name: mount filesystems
ansible.posix.mount:
fstype: nfs
opts: "{{ mount_options }}"
src: "{{ lif }}:{{ mount }}"
path: "{{ mountpoint }}"
state: ephemeral
become: yes
</code>
---
name: mount filesystems
ansible.posix.mount:
fstype: nfs
opts: "{{ mount_options }}"
src: "{{ lif }}:{{ mount }}"
path: "{{ mountpoint }}"
state: ephemeral
become: yes
mount_dirs.yml is in the same folder as filysystem.yml
Unfortunately this code is not working.
Do you know how I can fix this problem and make this code working?