summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-11-01 13:31:05 -0800
committerToshio Kuratomi <toshio@fedoraproject.org>2015-11-01 13:32:45 -0800
commit5e0d55ae5b4c6960a1041edd95d8a9f2f88c45f7 (patch)
tree1a61fca28e26b8e25f353fd420ae7fd986a9c0ce
parent4ec0536168649af5389f7064460876e154e11fec (diff)
downloadansible-5e0d55ae5b4c6960a1041edd95d8a9f2f88c45f7.tar.gz
Change the dict attribute collision warning to recommend using bracket notation
-rw-r--r--docsite/rst/playbooks_variables.rst22
1 files changed, 19 insertions, 3 deletions
diff --git a/docsite/rst/playbooks_variables.rst b/docsite/rst/playbooks_variables.rst
index d3314fbab0..b1ad224562 100644
--- a/docsite/rst/playbooks_variables.rst
+++ b/docsite/rst/playbooks_variables.rst
@@ -36,9 +36,25 @@ Variable names should be letters, numbers, and underscores. Variables should al
``foo-port``, ``foo port``, ``foo.port`` and ``12`` are not valid variable names.
-When you work with more complex data types like dictionaries and sets note that you should avoid keys which are valid attributes for a data type in Python.
-As a rule of thump, avoid all key names that start and end with two underscores for example ``__do_not_use__``.
-Also avoid any of the following words:
+YAML also supports dictionaries which map keys to values. For instance::
+
+ foo:
+ field1: one
+ field2: two
+
+You can then reference a specific field in the dictionary using either bracket
+notation or dot notation::
+
+ foo['field1']
+ foo.field1
+
+These will both reference the same value ("one"). However, if you choose to
+use dot notation be aware that some keys can cause problems because they
+collide with attributes and methods of python dictionaries. You should use
+bracket notation instead of dot notation if you use keys which start and end
+with two underscores (Those are reserved for special meanings in python) or
+are any of the known public attributes:
+
``add``, ``append``, ``as_integer_ratio``, ``bit_length``, ``capitalize``, ``center``, ``clear``, ``conjugate``, ``copy``, ``count``, ``decode``, ``denominator``, ``difference``, ``difference_update``, ``discard``, ``encode``, ``endswith``, ``expandtabs``, ``extend``, ``find``, ``format``, ``fromhex``, ``fromkeys``, ``get``, ``has_key``, ``hex``, ``imag``, ``index``, ``insert``, ``intersection``, ``intersection_update``, ``isalnum``, ``isalpha``, ``isdecimal``, ``isdigit``, ``isdisjoint``, ``is_integer``, ``islower``, ``isnumeric``, ``isspace``, ``issubset``, ``issuperset``, ``istitle``, ``isupper``, ``items``, ``iteritems``, ``iterkeys``, ``itervalues``, ``join``, ``keys``, ``ljust``, ``lower``, ``lstrip``, ``numerator``, ``partition``, ``pop``, ``popitem``, ``real``, ``remove``, ``replace``, ``reverse``, ``rfind``, ``rindex``, ``rjust``, ``rpartition``, ``rsplit``, ``rstrip``, ``setdefault``, ``sort``, ``split``, ``splitlines``, ``startswith``, ``strip``, ``swapcase``, ``symmetric_difference``, ``symmetric_difference_update``, ``title``, ``translate``, ``union``, ``update``, ``upper``, ``values``, ``viewitems``, ``viewkeys``, ``viewvalues``, ``zfill``.
.. _variables_in_inventory: