Ansible Playbook - List Variable

> Infrastructure as code > Ansible

1 - About

List variable

Advertising

3 - Initialization

a_list: []
packages: ['mapr-compat-suse', 'mapr-core', 'mapr-core-internal']

or from two_sources

unixodbc_cfg_sources:
  - source_name: source 1
    driver_file: /file/1
    driver_properties:
      property_1: value_1
  - source_name: source 2
    driver_file: /file/2
    driver_properties:
      property_2_1: value_2_1
      property_2_2: value_2_2

4 - Default

{{ mylist|default([]) }}

5 - Management

5.1 - Min

{{ list1 | min }}

5.2 - Max

{{ [3, 4, 2] | max }}

5.3 - List

{{ __java_packages | list }}

5.4 - Flatten

  • Flatten a list (same thing the flatten lookup does):
{{ [3, [4, 2] ] | flatten }}
  • Flatten only the first level of a list (akin to the items lookup):
{{ [3, [4, [2]] ] | flatten(levels=1) }}
Advertising

5.5 - In

'webserver' in group_names

5.6 - Loop

Ansible - Loop

- name: Install mapr-core
  vars:
    packages_Suse: ['mapr-compat-suse', 'mapr-core', 'mapr-core-internal']
    packages_RedHat: ['mapr-core', 'mapr-core-internal']
    packages_Debian: ['mapr-core', 'mapr-core-internal']
  package: name={{ item }} state=present
  with_items: "{{ vars['packages_' + ansible_os_family] }}"
  register: core_result

6 - Ref