I have a site. IML Playbook is when I use this configuration:
- Host: Target Tags: - setup_target Action: - Name: See some data debug: msg = {{hostvars [inventory_hostname] [ Ansety_lsb] .codename}}
Answer me an error:
PLAY [target] ************ **************************************************************************************************** ****************** ******************************************************************************** **************************************************************************************************** ******** ****************************************************************************************** ******************************** OK: [target] see some data] ******** **************************************************************************************************** ************* ******************************************************************** [Target] = & gt; One or more undefined variables: There is no element in the dict object ('u'relegies': u'14.04', you'mager_release ': u'14', u'codename ': u' trustee, u'id ': u' Buntu ', U Description': Yuubuntu 14.04.1 LTS 'Crop: All hosts have failed before - Cancel RECAP PLAY ******************************* **************************************************************************************************** *********************************** to ********** reuse ***************************************************************************************************** Goal: OK = 1 revenge = 0 unattainable = 1 = unsuccess
But if I I use the dot style, so:
--- # To set up our database, main playbook # - Host: Target Tags: - setup_target Functions: - Name: Some data See debug: msg = {{hostvars [inventory_hostname]. Codename}}
output is ok:
PLAY [target] ****** **************************************************************************************************** **************** ********************************** **************************** Fact ********************* ***************************** ********************* **************************************************************************************************** ******** Okay: ********************** Ok: [target] => {"Msg": "Trustworthy"} PLAY RECAPP ******************************************************************* **************************************************************************************************** *******************************************************************************S > Then, what is different? For me, both are equal?
Then, what's different? For me, both are equal?
How it comes down is how Ditches / Hash works in Python - and in detail, how they work in Genza 2 and Azbal.
If you have a data and you want the value of the foo
element, then you can use it like this: < / p> data [ "Foo"]
If you omit the quotes, you must be a variable named Fu.
data [foo] # does not work (yet)
jinja2 also lets you use dot style:
< Pre> data.foo
Let's trust the value "Foo" element number is 42. All these are true:
data ["foo"] = 42 data [Fu] # data does not work Foo = 42
Now, what if you have a variable name foo? In the following example we can still be 42 on the value of the key 'Foo', and 'bar' will be 13.
foo = "bar" data ["foo"] = 42 data [bar] = 13 data.foo = 42
In its original case To translate, keep in mind that inventory_hostname
and ansible_lsb
are both variables , string and even confusing, Ansible_lsb is a dictionary that means that your original bracket style spreads like this:
hostvars ["inventory_hostname"] [[u'release ': u'14.04', u'major_release ' : U'14 ',' Kodamam ': U'tristi', U'id ': U' Ubuntu, U Decryption ': U' Ubuntu 14.04.1 lts'}] ["Codename"]
Ops. As a key to a dict, a dict recursive cannibalism falls in the turtle.
What is the existence of your "dotted" style here?
hostvars ["inventory_hostname"] [ lsb = hostvars ["ansible_lsb"] ["codename"]
It can be translated more clearly: Inventory_hostname "] [" ansible_lsb "] LSB [" Codename "]
It's obvious what you want.
Comments
Post a Comment