Mount file share based on variable in loop

Greetings, folks!

I’m trying to have one single source-of-truth for file share info and mount individual shares on different servers depending on need.

Give a list of “these servers get these shares, those get those” and from that list loop over what to configure and mount.

I’ve been trying to use some magic via a ‘when’ conditional to configure and mount but nothing has gelled.

Suggestions would be greatly appreciated.

Thank you for your time and have a wonderful rest of your day!

  • mr. tim

Example setup…

vars:
app_server_mounts:

  • share0
  • share2

utility_server_mounts:

  • share2

cifs_file_share_mounts:

  • path: /mnt/share0
    src_host: nas.example.com
    src_path: share0
    fstype: cifs
    opts: sec=ntlmsspi,vers=3.0,rsize=61440,wsize=65536
    state: mounted

  • path: /mnt/share1
    src_host: nas.example.com
    src_path: share1
    fstype: cifs
    opts: sec=ntlmsspi,vers=3.0,rsize=61440,wsize=65536
    state: mounted

  • path: /mnt/share2
    src_host: nas.example.com
    src_path: share2
    fstype: cifs
    opts: sec=ntlmsspi,vers=3.0,rsize=61440,wsize=65536
    state: mounted

tasks:

  • name: Mount CIFS file shares
    mount:
    path: “{{ item.path }}”
    src: “//{{ item.src_host }}/{{ item.src_path }}”
    fstype: cifs
    opts: “{{ item.opts }}”
    state: “{{ item.state | default( ‘mounted’ ) }}”
    with_items: “{{ cifs_file_share_mounts }}”

I actually do this very thing. I have a role that just loops through a var inside the role. That role just uses the Mount task. With a lip. The role runs off the var exists. I can dig up the structure of it may help. On my phone now.

With a loop var*

Wei-Yen,
  With the quickness!

Looking forward to your code snippets.

Thanks!

- mr. tim

Hi Tim,

data structure in inventory (i use AWX) so just look at os_directory_file_items and mount_list