ansible.utils package¶
Submodules¶
ansible.utils.cmd_functions module¶
ansible.utils.color module¶
ansible.utils.display module¶
- 
class 
ansible.utils.display.Display(verbosity=0)[source]¶ Bases:
objectPrints a header-looking line with stars taking up to 80 columns of width (3 columns, minimum)
- 
display(msg, color=None, stderr=False, screen_only=False, log_only=False)[source]¶ Display a message to the user
Note: msg must be a unicode string to prevent UnicodeError tracebacks.
ansible.utils.encrypt module¶
ansible.utils.hashing module¶
- 
ansible.utils.hashing.secure_hash_s(data, hash_func=<built-in function openssl_sha1>)[source]¶ Return a secure hash hex digest of data.
- 
ansible.utils.hashing.secure_hash(filename, hash_func=<built-in function openssl_sha1>)[source]¶ Return a secure hash hex digest of local file, None if file is not present or a directory.
- 
ansible.utils.hashing.checksum(filename, hash_func=<built-in function openssl_sha1>)¶ Return a secure hash hex digest of local file, None if file is not present or a directory.
- 
ansible.utils.hashing.checksum_s(data, hash_func=<built-in function openssl_sha1>)¶ Return a secure hash hex digest of data.
ansible.utils.listify module¶
ansible.utils.module_docs module¶
- 
ansible.utils.module_docs.get_docstring(filename, verbose=False)[source]¶ Search for assignment of the DOCUMENTATION and EXAMPLES variables in the given file. Parse DOCUMENTATION from YAML and return the YAML doc or None together with EXAMPLES, as plain text.
DOCUMENTATION can be extended using documentation fragments loaded by the PluginLoader from the module_docs_fragments directory.
ansible.utils.path module¶
ansible.utils.unicode module¶
- 
ansible.utils.unicode.to_unicode(obj, encoding='utf-8', errors='replace', nonstring=None)[source]¶ Convert an object (:obj:) into a :unicode: string.
Parameters: - obj – Object to convert to a 
unicodestring. This should normally be a bytestr - encoding – What encoding to try converting the byte 
stras. Defaults to utf-8 - errors – If errors are found while decoding, perform this action.
Defaults to 
replacewhich replaces the invalid bytes with a character that means the bytes were unable to be decoded. Other values are the same as the error handling schemes in the codec base classes. For instancestrictwhich raises an exception andignorewhich simply omits the non-decodable characters. - nonstring – 
How to treat nonstring values. Possible values are:
simplerepr: Attempt to call the object’s “simple representation” method and return that value. Python-2.3+ has two methods that try to return a simple representation: object.__unicode__()andobject.__str__(). We first try to get a usable value fromobject.__unicode__(). If that fails we try the same withobject.__str__().empty: Return an empty unicodestringstrict: Raise a TypeErrorpassthru: Return the object unchanged repr: Attempt to return a unicodestring of the repr of the objectDefault is
simplerepr 
Raises: - TypeError – if 
nonstringisstrictand a non-basestringobject is passed in or ifnonstringis set to an unknown value - UnicodeDecodeError – if 
errorsisstrictandobjis not decodable using the given encoding 
Returns: unicodestring or the original object depending on the value ofnonstring.Usually this should be used on a byte
strbut it can take both bytestrandunicodestrings intelligently. Nonstring objects are handled in different ways depending on the setting of thenonstringparameter.The default values of this function are set so as to always return a
unicodestring and never raise an error when converting from a bytestrto aunicodestring. However, when you do not pass validly encoded text (or a nonstring object), you may end up with output that you don’t expect. Be sure you understand the requirements of your data, not just ignore errors by passing it through this function.- obj – Object to convert to a 
 
- 
ansible.utils.unicode.to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None)[source]¶ Convert an object into a byte
strParameters: - obj – Object to convert to a byte 
str. This should normally be aunicodestring. - encoding – Encoding to use to convert the 
unicodestring into a bytestr. Defaults to utf-8. - errors – 
If errors are found while encoding, perform this action. Defaults to
replacewhich replaces the invalid bytes with a character that means the bytes were unable to be encoded. Other values are the same as the error handling schemes in the codec base classes. For instancestrictwhich raises an exception andignorewhich simply omits the non-encodable characters. - nonstring – 
How to treat nonstring values. Possible values are:
simplerepr: Attempt to call the object’s “simple representation” method and return that value. Python-2.3+ has two methods that try to return a simple representation: object.__unicode__()andobject.__str__(). We first try to get a usable value fromobject.__str__(). If that fails we try the same withobject.__unicode__().empty: Return an empty byte strstrict: Raise a TypeErrorpassthru: Return the object unchanged repr: Attempt to return a byte strof therepr()of the objectDefault is
simplerepr. 
Raises: - TypeError – if 
nonstringisstrictand a non-basestringobject is passed in or ifnonstringis set to an unknown value. - UnicodeEncodeError – if 
errorsisstrictand all of the bytes ofobjare unable to be encoded usingencoding. 
Returns: byte
stror the original object depending on the value ofnonstring.Warning
If you pass a byte
strinto this function the bytestris returned unmodified. It is not re-encoded with the specifiedencoding. The easiest way to achieve that is:to_bytes(to_unicode(text), encoding='utf-8')
The initial
to_unicode()call will ensure text is aunicodestring. Then,to_bytes()will turn that into a bytestrwith the specified encoding.Usually, this should be used on a
unicodestring but it can take either a bytestror aunicodestring intelligently. Nonstring objects are handled in different ways depending on the setting of thenonstringparameter.The default values of this function are set so as to always return a byte
strand never raise an error when converting from unicode to bytes. However, when you do not pass an encoding that can validly encode the object (or a non-string object), you may end up with output that you don’t expect. Be sure you understand the requirements of your data, not just ignore errors by passing it through this function.- obj – Object to convert to a byte 
 
- 
ansible.utils.unicode.to_str(obj, encoding='utf-8', errors='replace', nonstring=None)¶ Convert an object into a byte
strParameters: - obj – Object to convert to a byte 
str. This should normally be aunicodestring. - encoding – Encoding to use to convert the 
unicodestring into a bytestr. Defaults to utf-8. - errors – 
If errors are found while encoding, perform this action. Defaults to
replacewhich replaces the invalid bytes with a character that means the bytes were unable to be encoded. Other values are the same as the error handling schemes in the codec base classes. For instancestrictwhich raises an exception andignorewhich simply omits the non-encodable characters. - nonstring – 
How to treat nonstring values. Possible values are:
simplerepr: Attempt to call the object’s “simple representation” method and return that value. Python-2.3+ has two methods that try to return a simple representation: object.__unicode__()andobject.__str__(). We first try to get a usable value fromobject.__str__(). If that fails we try the same withobject.__unicode__().empty: Return an empty byte strstrict: Raise a TypeErrorpassthru: Return the object unchanged repr: Attempt to return a byte strof therepr()of the objectDefault is
simplerepr. 
Raises: - TypeError – if 
nonstringisstrictand a non-basestringobject is passed in or ifnonstringis set to an unknown value. - UnicodeEncodeError – if 
errorsisstrictand all of the bytes ofobjare unable to be encoded usingencoding. 
Returns: byte
stror the original object depending on the value ofnonstring.Warning
If you pass a byte
strinto this function the bytestris returned unmodified. It is not re-encoded with the specifiedencoding. The easiest way to achieve that is:to_bytes(to_unicode(text), encoding='utf-8')
The initial
to_unicode()call will ensure text is aunicodestring. Then,to_bytes()will turn that into a bytestrwith the specified encoding.Usually, this should be used on a
unicodestring but it can take either a bytestror aunicodestring intelligently. Nonstring objects are handled in different ways depending on the setting of thenonstringparameter.The default values of this function are set so as to always return a byte
strand never raise an error when converting from unicode to bytes. However, when you do not pass an encoding that can validly encode the object (or a non-string object), you may end up with output that you don’t expect. Be sure you understand the requirements of your data, not just ignore errors by passing it through this function.- obj – Object to convert to a byte 
 
ansible.utils.vars module¶
- 
ansible.utils.vars.combine_vars(a, b)[source]¶ Return a copy of dictionaries of variables based on configured hash behavior
- 
ansible.utils.vars.merge_hash(a, b)[source]¶ Recursively merges hash b into a so that keys from b take precedence over keys from a
- 
ansible.utils.vars.isidentifier(ident)[source]¶ Determines, if string is valid Python identifier using the ast module. Orignally posted at: http://stackoverflow.com/a/29586366