2 ms·
Really, I just want to know how ansible provides for token substitution, so I could reuse a value defined elsewhere, so I could define all the subdirectories in
by philipov 9y ago
Really, I just want to know how ansible provides for token substitution, so I could reuse a value defined elsewhere, so I could define all the subdirectories in a playbook relative to a single base directory.
YAML doesn't offer a syntax for writing "${BASEDIR}/subdir". There's gotta be something in ansbile that makes this possible, but I can't find it.
- zo1 9y agoThat "thing" that you're referring to is handled by Ansible, and not by YAML. It uses the Jinja2 templating engine. And I would assume Ansible uses some sort of scoping order/rules in order to provide values for the template generation. E.g. look here in the Ansible docs: http://docs.ansible.com/ansible/latest/playbooks_loops.html#standard-loops http://docs.ansible.com/ansible/latest/playbooks_loops.html#... It provides a construct that allows you to loop over a sub-list of YAML items, and then let's you use the looped-variable in a string-substitution via the templating language. That's the name: "{{ item }}" that you see there. Edit. Typo
- philipov 9y agoThank you! this is what I've been looking for, but searches for token, substitution, and "defining subdirectories" have not led to this. Calling it a loop is confusing. It seems the values have to be defined in some other file, so I couldn't chain them, though. Suppose I want to write something like... paths: BASEDIR: /somedir SUBDIR1: {{ paths:BASEDIR }}/subdir1 SUBDIR2: {{ paths:SUBDIR1 }}/subdir2 Doesn't seem like that would work. I would end up putting all my definitions into a separate file.