简体   繁体   中英

Ansible - Wrapper of python interpreter

Ansible uses YAML syntax mainly has key-value pairs, where every value can be

a simple value (number or string)

or

a list

or

a key-value pair(nested)


Anchoring a value, Type conversion in YAML is just a pre-processing option.


1)

From the data structure aspect,

Is YAML syntax a dictionary of dictionary?

2)

For command: ansible -m shell 'hostname' all , Is ansible a wrapper of python interpreter? taking multiple command line options...

From the data structure aspect,

Is YAML syntax a dictionary of dictionary?

No. YAML syntax models a directed graph. Your assumptions on YAML given initially are wrong. In YAML, a value is one of three things:

  • A scalar (number, string, date, …)
  • A sequence (list of values)
  • A mapping (list of key-value pairs where both keys and values are any kind of value)

Since any non-scalar value can contain other non-scalar values, YAML can represent a tree of arbitrary depth – so it's not necessarily a dictionary of dictionaries.

Now, YAML also allows to have an anchor on any value, and reference that value later via alias:

anchored value: &anchor My value
alias: *anchor

Here, *alias references the anchored scalar value My value . This can be used to define cyclic graphs:

--- &root   # this annotates the root sequence;
- one
- two       # simple sequence items
- three
- *root     # reference to the sequence, meaning that the sequence contains itself

Mind that both sequence and mappings are usually started implicitly in YAML syntax. If children are key/value pairs, it's a mapping (first example); if children are list items, it's a sequence (second example). --- starts the document and is usually omitted.

For command: ansible -m shell 'hostname' all, Is ansible a wrapper of python interpreter? taking multiple command line options...

See the man page of the ansible command . You are probably looking for the -a ARGS option. I am unsure what you would consider a wrapper of the Python interpreter and you may want to clarify what you actually want to do. Generally, the answer to that is no .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM