I am new to ansible and followed the instruction here which gives two notations for referencing key-value dictionaries.
foo['field1']
foo.field1
and says "Bracket notation always works". I try with
vars:
- london:
- nodename : music0
- card: Headphone
- mixer: Hardware
- debug:
msg: nodename "{{ london[0] }} "
- debug:
msg: nodename "{{ london['nodename'] }} "
The first wint reference [0] seems ok:
TASK [debug] *******************************************************************
ok: [127.0.0.1] => {
"msg": "nodename \"{u'nodename': u'music0'} \""
}
but not the bracket notation:
fatal: [127.0.0.1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'list object' has no attribute 'nodename'\n\nThe error appears to be in '/home/frank/Data/ansibleHost/testVars.yml': line 29, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n"}
What is the difference to the published example? I admit that I do not understand the error message... the list object should be london which has an attribute - or do I misunderstand the variable declaration?
I would appreciate a recommendation for a comprehensive tutorial!