ansible.inventory package¶
- 
class 
ansible.inventory.Inventory(loader, variable_manager, host_list='/etc/ansible/hosts')[source]¶ Bases:
objectHost inventory for ansible.
- 
get_hosts(pattern='all', ignore_limits_and_restrictions=False)[source]¶ Takes a pattern or list of patterns and returns a list of matching inventory host names, taking into account any active restrictions or applied subsets
- 
classmethod 
split_host_pattern(pattern)[source]¶ Takes a string containing host patterns separated by commas (or a list thereof) and returns a list of single patterns (which may not contain commas). Whitespace is ignored.
Also accepts ‘:’ as a separator for backwards compatibility, but it is not recommended due to the conflict with IPv6 addresses and host ranges.
Example: ‘a,b[1], c[2:3] , d’ -> [‘a’, ‘b[1]’, ‘c[2:3]’, ‘d’]
- 
clear_pattern_cache()[source]¶ called exclusively by the add_host plugin to allow patterns to be recalculated
- 
restrict_to_hosts(restriction)[source]¶ Restrict list operations to the hosts given in restriction. This is used to batch serial operations in main playbook code, don’t use this for other reasons.
- 
subset(subset_pattern)[source]¶ Limits inventory results to a subset of inventory that matches a given pattern, such as to select a given geographic of numeric slice amongst a previous ‘hosts’ selection that only select roles, or vice versa. Corresponds to –limit parameter to ansible-playbook
- 
is_file()[source]¶ Did inventory come from a file? We don’t use the equivalent loader methods in inventory, due to the fact that the loader does an implict DWIM on the path, which may be incorrect for inventory paths relative to the playbook basedir.
- 
is_directory(path)[source]¶ Is the inventory host list a directory? Same caveat for here as with the is_file() method above.
- 
 
Subpackages¶
Submodules¶
ansible.inventory.dir module¶
ansible.inventory.expand_hosts module¶
This module is for enhancing ansible’s inventory parsing capability such that it can deal with hostnames specified using a simple pattern in the form of [beg:end], example: [1:5], [a:c], [D:G]. If beg is not specified, it defaults to 0.
If beg is given and is left-zero-padded, e.g. ‘001’, it is taken as a formatting hint when the range is expanded. e.g. [001:010] is to be expanded into 001, 002 ...009, 010.
Note that when beg is specified with left zero padding, then the length of end must be the same as that of beg, else an exception is raised.
- 
ansible.inventory.expand_hosts.detect_range(line=None)[source]¶ A helper function that checks a given host line to see if it contains a range pattern described in the docstring above.
Returnes True if the given line contains a pattern, else False.
- 
ansible.inventory.expand_hosts.expand_hostname_range(line=None)[source]¶ A helper function that expands a given line that contains a pattern specified in top docstring, and returns a list that consists of the expanded version.
The ‘[‘ and ‘]’ characters are used to maintain the pseudo-code appearance. They are replaced in this function with ‘|’ to ease string splitting.
References: http://ansible.github.com/patterns.html#hosts-and-groups