How to pass a dynamic variable into an Ansible role -


for each of our servers (webs , perls), have different mount points each type of servers. web servers, want use entries "web_mounts" , perls "perl_mounts."

if hard code "web_mounts" "with_items," works fine. otherwise, tells me "nfs_group" undefined.

top level

roles:   - { role: webs, nfs_group: "web_mounts" } 

roles/nfs_mounts/vars/main.yml

--- web_mounts:   - { source: "nfs.local:/nfs/web1, dest: "/web1", opts: "rw,noatime" }   - { source: "nfs.local:/nfs/web2, dest: "/web2", opts: "rw,noatime" }  perl_mounts:   - { source: "nfs.local:/nfs/perl1, dest: "/perl1", opts: "rw,noatime" }   - { source: "nfs.local:/nfs/perl2, dest: "/perl2", opts: "rw,noatime" } 

roles/nfs_mounts/tasks/main.yml

- name: create fstab entries   mount: fstab=nfs state=present opts="{{ item.opts }}" src="{{ item.source }}" name="{{ item.dest }}"   with_items: "{{ nfs_group }}" 

group mounts in dict this:

--- mounts:   web_mounts:     - { source: "nfs.local:/nfs/web1", dest: "/web1", opts: "rw,noatime" }     - { source: "nfs.local:/nfs/web2", dest: "/web2", opts: "rw,noatime" }   perl_mounts:     - { source: "nfs.local:/nfs/perl1", dest: "/perl1", opts: "rw,noatime" }     - { source: "nfs.local:/nfs/perl2", dest: "/perl2", opts: "rw,noatime" } 

and access dict elements this:

- name: create fstab entries   mount: fstab=nfs state=present opts="{{ item.opts }}" src="{{ item.source }}" name="{{ item.dest }}"   with_items: "{{ mounts[nfs_group] }}" 

as "nfs_group undefined" error, check call roles correctly – role name "nfs_mounts" , top level playbook applies role "webs".


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -