Подробный разбор простых и сложных конструкций в синтаксисе Ansible
MIT License
, , , . , . , , , . Ansible. .
[examples](examples/). ``debug`` , . - - .
.
. . , with_items , .
Ansible - . , . Ansible 2.3.1.0.
, Ansible. [](#), .
Ansible. , . ``yaml`` , () ! . , :
soft:
- htop
- atop
- tshark
- mtr
``with_items``. ``"{{ soft }}"``, ``"{{ item }}"``.
:
- name: Utils | Ubuntu | Install basic utilities
apt:
pkg: "{{ item }}"
state: present
with_items: "{{ soft }}"
. . :
soft: ['htop', 'atop', 'tshark', 'mtr']
, . , .
``:``. , . .
swap_file:
filename: "swapfile"
location: "/"
size: 512
status: "install"
. ``swap_file`` , ``filename``, ``location``, ``size``, ``status`` - . ``swapfile``, ``/``, ``512``, ``install`` .
(), . : "We want to install file to /. File should be called swapfile and use 512 MB of disk space."
- name: Simple dictionary pointing.
debug:
msg: "We want to {{ swap_file.status }} file to {{ swap_file.location }}. File should be called {{ swap_file.filename }} and use {{ swap_file.size }} MB of disk space."
, Ansible .
-, . , . with_dict
. {{ item.key }}
{{ item.value }}
. .
- name: Usage of with_dict helps here.
debug:
msg: "Current key is {{ item.key }}. Current key value is {{ item.value }}."
with_dict: "{{ swap_file }}"
, . , , . :
swap_file: {filename: "swapfile", location: "/", size: 512, status: "install"}
[](examples/dictionary.yml) [ ](examples/dictionary_alt.yml) . 10 . .
, . . . , .
, (, , , ). .
swap_files:
- filename: "first_swapfile"
location: "/"
size: 512
status: "install"
- filename: "second_swapfile"
location: "/other"
size: 1024
status: "install"
``with_items``, . . [](#--) , ``"{{ swap_file.status }}"``, ``"{{ swap_file.location }}"``, ``"{{ swap_file.filename }}"``, ``"{{ swap_file.size }}"``?
, ``with_items``, ``item``.
- name: "Same strings for several dictionary items:"
debug:
msg: "We want to {{ item.status }} file to '{{ item.location }}'. File should be called '{{ item.filename }}' and use {{ item.size }} MB of disk space."
with_items: "{{ swap_files }}"
, , , . .
, , ``with_dict`` .
with_items
, . .
, :
- name: Utils | Ubuntu | Install basic utilities
apt:
pkg: "{{ item }}"
state: present
with_items:
- htop
- atop
- tshark
- mtr
, , . . \ :
soft:
- htop
- atop
- tshark
- mtr
:
- name: Utils | Ubuntu | Install basic utilities
apt:
pkg: "{{ item }}"
state: present
with_items: "{{ soft }}"