Hi,

didn't realize you were using the ansible_mounts fact, i understand what 
you are trying to do here and i think there might be a way..

how about you try doing this :

Define a new  var "mount_options" which links mount names to options 
predefined by you, then use it in your mount command to dynamically fill 
the options argument.

what i mean is this..

---
- hosts: all
  gather_facts: no
  vars:
   -  mount_options:
        "/home": "defaults"
        "/var": "defaults,nosuid"
        "/": "defaults"
  tasks:
   - name: Secure Mount options
     mount: name={{ item.mount }} src='{{ item.device }}' state=present 
fstype={{ item.fstype }} opts={{ mount_options[item.mount] }}
     with_items: ansible_mounts
     when: mount_options[item.mount] is defined

this should work for you, all you need is define all your possible mount -> 
mount options in that variable "mount_options", the when conditional 
statement at the end is important, so it won't fail if it encounters a 
mount that doesn't have options set by you in the "mount_options" variable.

here is what i used to test that this concept actually works :

---
- hosts: all
  gather_facts: no
  vars:
   -  mount_options:
        "/home": "defaults"
        "/var": "defaults,nosuid"
        "/": "defaults"
  tasks:
    - name: test vars
      debug: msg="{{ item.mount }} and {{ mount_options[item.mount] }}"
      with_items:
        - { mount: '/home', fs: 'ext4'}
        - { mount: '/var', fs: 'ext4'}
        - { mount: '/', fs: 'ext4'}
        - { mount: 'swap', fs: 'swap'}
      when: mount_options[item.mount] is defined





On Saturday, August 2, 2014 9:05:07 AM UTC+2, [email protected] wrote:
>
> Friends,
>
> I'd like to iterate over ansible_mounts and set custom options for /some/ 
> mount points, like so
>
> /var: defaults,nosuid
> /home: defaults,nosuid,nodev
> /: defaults
>
> - name: Secure Mount options
>   mount: name={{ item.mount }} src='{{ item.device }}' state=present 
> fstype={{ item.fstype }} opts={{ ??? }}
>   with_items: ansible_mounts
>
> How can I combine the list of vars within my loop. So that opts= is filled 
> with the value looked up depending on the mount point?
>
> Thanks for any pointers!
> Stephan
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/37afd2b2-3cc3-48e5-90cf-638ac868760f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to