Ansible Data Structures

Type of data structures Since Ansible is based on Python. There are two main data structures in Ansible: list and dictionary. List Initialization of a list - name: Initialize an empty list set_fact: list: [] Result is: {"list": []} Append element to a list - name: Append element to list set_fact: list: "{{ list + [ 'element_1' ] }}" Result is: {"list": ["element_1"]} Append multiple elements to a list - name: Get list of files in current directory shell: "ls" register: ls_files - name: Append filtered elements (only yaml file) to list set_fact: list: "{{ list + [ item ] }}" loop: "{{ ls_files....

December 18, 2023 · 3 min