I have a var file with mount points that should be mounted. A common entry 
for /home goes on all servers. Some servers (e.g. web and perl) have their 
own set of mount points. I'm using Ansible pull and I build the element 
dynamically. So for webs, I reach in by using "aws_mounts[nfs_group]", with 
"nfs_group" equal to "web_mounts" for web servers and "perl_mounts" for 
perl servers. Generating the variable isn't an issue. However, some servers 
do not have "nfs_group" defined and the task will fail w/ a "variable is 
undefined error"

I tried the following:

# tasks

- name: Create fstab entries
  mount:
      fstype: nfs
      state: mounted
      opts: "{{ item.opts }}"
      src: "{{ item.source }}"
      name: "{{ item.dest }}"
  when: item.source is defined
  with_items:
      - "{{ aws_mounts[nfs_group] | default({}) }}"
      - "{{ aws_mounts.common }}"


# vars/main.yml
---
  aws_mounts:
    common:
      - { source: "/home",      dest: "/opt/ansible-home",                 
         opts: "bind" }
    web_mounts:
      - { source: "/tmp",      dest: "/opt/ansible-web",                   
       opts: "bind" }

-- 
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/b90b52b3-5954-4cba-90f3-a769fc774243%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to