4 ms·
I like YAML, but it needs shell-style $ substitution tokens to allow constructing values from previously-defined values (such as when defining a PATH variable,
by philipov 9y ago
I like YAML, but it needs shell-style $ substitution tokens to allow constructing values from previously-defined values (such as when defining a PATH variable, or subdirectory).
To that end, I'm going down the path of writing my own extension to YAML. Can you recommend one that already exists that accomplishes this goal? I don't see an alternative, because I can't find something standard that actually meets the requirements.
Shell scripting languages are platform-specific, and not hierarchically structured, so that's what I'm trying to replace to begin with.
Ansible requires a central server and full commitment to immutable deployments, so it's too heavy for a package manager that can support piecemeal adoption or that could be used by researchers doing ad-hoc development. It doesn't support windows anyway (linux for windows subsystem doesn't count).
Conda is nice, but even though it uses YAML for defining dependencies, it nonetheless falls back to shell scripts for environment variables, and doesn't offer features for environment modularization.
EDIT: Hierarchical structure is needed to be able to both express and manipulate configs for software that expects input as XML, so ConfigParser isn't good enough. Setting a value to a blob of JSON or XML denies the ability to operate on that blob to do things like merge subtrees. Instead, I'm using ruamel.yaml as my starting point, and adding post-processing after it's converted to nested dict/lists.
- zzzeek 9y ago> Ansible requires a central server and full commitment to immutable deployments i dont know what that means. Ansible is like a much more structured form of shell scripting, you can run ansible playbooks from anywhere to do anything and make them do anything. i don't know what an "immutable deployment" is. also ansible has nothing to do with "config", YAML is used as a declarative scripting language rather than a config file format.
- philipov 9y agoReally, 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.
- detaro 9y agoIn what way does Ansible require a central server? you can ask Ansible to run a bunch of playbooks from the shell, without anything else involved.
- philipov 9y agoThis might just be my own misunderstanding.