I'd like to have a pattern for roles where I can:

1) set default values in defaults/default.yml
2) override certain parts of a deep data structure in defaults/{{ansible_distribution}}.yml 3) allow individual instantiations of that role to override specific parts of it.


I have a complex data structure for configuring the settings of a certain software.

A more or less complete yaml description of the data structure might be something like:
--
foo_app:
  config_dir: /etc/foo
  run_dir: /var/cache/foo
  pid_file: /var/run/foo/foo.pid
  user: foo-user
  group: foo-group
  interface: *
  port: 8888
  unix_socket: /var/run/foo.socket
  settings:
    cluster_members:
      - hostA
      - hostB
      - hostC           
    cache_size: 8192
    client_timeout: 8s
    cluster_timeout: 1s
    ...

In other words, a deep structure which is a dict, where the values of some of the (top-level) keys could be various datatypes, including lists or dicts themselves.

I'd like to have templates which use this data structure look like:

    {% for key, value in foo_app.settings.iteritems() | sort %}
    {{ key }} = {{ value }}
    {% endfor %}

partly because it's convenient, and partly because namespacing under foo_app is good defensive programming to reduce the chance that other roles will step on my vars.

So in summary, what do we think is the best way to allow (1), (2) & (3) without

a) requiring that the data structure is flattened into individual vars:

--
foo_app_config_dir: /etc/foo
foo_app_settings_clustermembers:
  - hostA
  - hostB
  - hostC

OR

b) Ensuring that *every* declaration of the data structure contains *every* element of the data structure, not just the ones we want to override.

Of course, I realise that I might just be going about this all wrong (or at least not Anisbly) - if that's the case, please feel free to point me at docs (or Galaxy roles or github repos for learning by example) that show the Right Way to approach roles with elegance with regards to multi-distribution support and other cases that call for inheritance/override flexibility.
--
Duncan Hutty
http://www.allgoodbits.org

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5501C77D.9080208%40allgoodbits.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to