ansible.parsing package¶
Subpackages¶
Submodules¶
ansible.parsing.dataloader module¶
- 
class 
ansible.parsing.dataloader.DataLoader[source]¶ Bases:
objectThe DataLoader class is used to load and parse YAML or JSON content, either from a given file name or from a string that was previously read in through other means. A Vault password can be specified, and any vault-encrypted files will be decrypted.
Data read from files will also be cached, so the file will never be read from disk more than once.
Usage:
dl = DataLoader() # optionally: dl.set_vault_password(‘foo’) ds = dl.load(‘...’) ds = dl.load_from_file(‘/path/to/file’)- 
load(data, file_name='<string>', show_content=True)[source]¶ Creates a python datastructure from the given data, which can be either a JSON or YAML string.
- 
set_basedir(basedir)[source]¶ sets the base directory, used to find files when a relative path is given
- 
path_dwim_relative(path, dirname, source)[source]¶ find one file in either a role or playbook dir with or without explicitly named dirname subdirs
Used in action plugins and lookups to find supplemental files that could be in either place.
- 
read_vault_password_file(vault_password_file)[source]¶ Read a vault password from a file or if executable, execute the script and retrieve password from STDOUT
- 
get_real_file(file_path)[source]¶ If the file is vault encrypted return a path to a temporary decrypted file If the file is not encrypted then the path is returned Temporary files are cleanup in the destructor
- 
 
ansible.parsing.mod_args module¶
- 
class 
ansible.parsing.mod_args.ModuleArgsParser(task_ds={})[source]¶ Bases:
objectBase module argument parsing class.
There are several ways a module and argument set can be expressed:
# legacy form (for a shell command) - action: shell echo hi # common shorthand for local actions vs delegate_to - local_action: shell echo hi # most commonly: - copy: src=a dest=b # legacy form - action: copy src=a dest=b # complex args form, for passing structured data - copy: src: a dest: b # gross, but technically legal - action: module: copy args: src: a dest: b # extra gross, but also legal. in this case, the args specified # will act as 'defaults' and will be overridden by any args specified # in one of the other formats (complex args under the action, or # parsed from the k=v string - command: 'pwd' args: chdir: '/tmp'This class has some of the logic to canonicalize these into the form:
- module: <module_name> delegate_to: <optional> args: <args>
Args may also be munged for certain shell command parameters.
ansible.parsing.quoting module¶
ansible.parsing.splitter module¶
- 
ansible.parsing.splitter.parse_kv(args, check_raw=False)[source]¶ Convert a string of key/value items to a dict. If any free-form params are found and the check_raw option is set to True, they will be added to a new parameter called ‘_raw_params’. If check_raw is not enabled, they will simply be ignored.
- 
ansible.parsing.splitter.split_args(args)[source]¶ Splits args on whitespace, but intelligently reassembles those that may have been split over a jinja2 block or quotes.
When used in a remote module, we won’t ever have to be concerned about jinja2 blocks, however this function is/will be used in the core portions as well before the args are templated.
example input: a=b c=”foo bar” example output: [‘a=b’, ‘c=”foo bar”’]
Basically this is a variation shlex that has some more intelligence for how Ansible needs to use it.