Remove empty element from list in ansible

Viewed 388
input:
  - tests_to_run

tasks:
  modify_user_input:
         < Remove the empty elements from tests_to_run>


Have been searching for hours. Does anyone know a way to filter the input, so I can manipulate the tests_to_run list, so it does not have any empty elements.

Sample input and output

Sample tests_to_run = ['test_a','','test_b','test_c','yrls']
Expected variable to be used in later tasks test_to_run_clean = ['test_a','test_b','test_c','yrls']
1 Answers

To remove the empty element from the list:

---

- name: Sample playbook
  connection: local
  gather_facts: false
  hosts: localhost
  vars:
    mylist:
      - abc
      - def
      - 
      - jkl

  tasks:
- set_fact:
        mylist: "{{ mylist|select()|list }}"
Related