Search code examples
ansiblemultilineansible-filter

How to split multiple filters into multiple lines with Ansible?


Here's a task I have on my playbook:

- name: Parse 'LANGUAGE' from current locale and language configuration
  set_fact:
    locale_language: "{{ locale_status.stdout | regex_search('LANGUAGE=([^\n]+)', '\\1') | default([locale_lang], true) | first }}"

I'm trying to find a way to split that multiple filters line into multiple lines to make it more readable, but nothing I do works. Is it even possible without making the whole thing more complicated to read?


Solution

  • You can try something like this,

    - name: Parse 'LANGUAGE' from current locale and language configuration
      set_fact:
        locale_language: "{{ locale_status.stdout \
                         | regex_search('LANGUAGE=([^\n]+)', '\\1') \
                         | default([locale_lang], true) \
                         | first }}"
    

    As I have tested this below task and it works fine,

    tasks:
        - set_fact:
            locale_language: "{{ shubham \
                             | quote }}"
        - debug:
            msg: "{{ locale_language }}"