Hey People,
Having some trouble using YAML dictionaries.
I'm refactoring my variable structure in a role a wrote a while ago.
The variables used to all look like: sensu_api_host, but I wanted to move to
using dictionaries, so when referencing them it wouldn't be:
{{ sensu_api_host }}
it'd be:
{{ sensu['api']['host'] }}
In doing so, I've restructured my roles' defaults/main.yml like so:
sensu:
api:
host: "{{ groups['sensu_masters'][0] }}"
port: 4567
ssl: "false"
user_name: admin
password: secret
uchiwa_path: ''
timeout: 5000
client_config: client.json.j2
config_path: /opt/local/etc/sensu
gem_state: present
plugin_gem_state: present
user_name: sensu
group_name: sensu
include_plugins: true
include_dashboard: false
master: false
Though, I have a problem. Lookups for the above variables work fine... until I
try to assign them values elsewhere, where it should take precedence.
Some of the key values above are clobbered when they are defined elsewhere,
such as host_vars/hostname.yml or group_vars/groupname.yml.
It seems that if I want to define one of the nested keys' value elsewhere, it
ruins the dictionary lookup for all other child keys who share that parent.
For example, above you can see that sensu['include_dashboard'] is set to false.
If I want to set this to `true` for a particular host, in
host_vars/hostname.yml like so:
---
sensu:
include_dashboard: true
This then clobbers the lookup for any other child keys belonging to the sensu
dictionary.
So, for example, lookups for sensu['group_name'] will fail with the
following:fatal: [my.host.tld] => One or more undefined variables: 'dict
object' has no attribute 'group_name'
When trying to evaluate the following play:
- name: Ensure the Sensu group is present
group: name={{ sensu['group_name'] }}
state=present
I'm not sure what it is I'm doing wrong here - I'd really appreciate any help!
For the record: I'm running Ansible 1.9.4
Thanks in advance,
Calum
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/01207bb1-325a-4d80-93ad-ab501a60d422%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.