Skip to content

frankhjung/ansible-filters

Repository files navigation

Ansible Filters: a short introduction

A introductory presentation (~20 minutes) on Ansible filters.

Run the Example Playbook

Run specific filter examples using associated tags:

ansible-playbook filter-examples.yaml --list-tags

ansible-playbook filter-examples.yaml --tag create
ansible-playbook filter-examples.yaml --tag subset
ansible-playbook filter-examples.yaml --tag manipulate
ansible-playbook filter-examples.yaml --tag other
ansible-playbook filter-examples.yaml --tag regex

ansible-playbook filter-examples.yaml --tag test

Pipe or Method Call?

Jinja filters can be invoked using a method call:

- debug:
    msg: "{{ martin.name.upper() }}" # jinja filter
TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "MARTIN D'VLOPER"
}

This does not seem to work for Ansible filters, instead pipe:

- debug:
    msg: "{{ martin.name | hash }}" # ansible filter
TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "77844c7c15c84f66aa6ada7c6e2761f4aecd52c0"
}

Notes

executed on Ansible controller

This is done to minimize the requirements on the target (Jinja2 is only required on the controller) and to be able to pass the minimal information needed for the task, so the target machine does not need a copy of all the data that the controller has access to.

Presentation

Presentation produced using Beamer LaTeX:

Logo

Logo created from montage of images in figures directory using ImageMagick:

montage ansible-logo.png thelinuxfoundation-logo.png acm-logo.png themarlogroup-logo.png -geometry 48x48 logos.png