I’m new to ansible. I have used the group_vars/dbservers file to reference a single simple variable but now trying to link a file containing complex variables list.
Put most simply what is the syntax for adding a file or file reference (similar to vars_files) to group_vars for a given role?
I’m guessing I need a file group_vars/common.yml but vars_files doesn’t seem to work here.
I get the vars_files inside the playbook to work successfully as below but was unsuccessful concerning the group_vars solution for a role.
Following the example from ‘coderwall.com - Use ‘with_items’ with complex arguments to simplify handler logic’
- name: template everything for fuser
template: src=${item.src} dest=${item.dest} with_items: ${fooserv_template_files} notify: - restart fooserv
Of course we could also define the list you were walking over in another file, like a “groupvars/webservers" file to define all the variables needed for the webservers group, or a YAML file loaded from the "varsfiles” directive inside the playbook. Look how this can clean up if we do.
My issue is that if I run the my common playbook standalone the file is included via vars_files but if I run the web playbook which only executes the common role tasks the file contents are unavailable throwing “One or more undefined variables: ‘str object’ has no attribute ‘name’” . I’ve followed the directory layout of Ansible Best Practices.