ansible with_together 中的复杂循环

yan*_*ael 5 ansible

如果我使用 with_together,如何跳过列表中的空项目?

看下面的代码:

- name: get data_files list
  shell: ls -l data_files | awk -F " " {'print $9'}
  register: csv_file_list
- debug: var=csv_file_list

- name: get table name list
  shell: ls -l data_files/ | awk -F " " {'print $9'} | sed -e "s/.csv//g" | sed -e "s/-/./g"
  register: table_list
- debug: var=table_list

- name: copy table from csv to demo db
  shell: psql -U postgres -d demo -c "\copy {{ item.1 }} from /home/ubuntu/data_files/{{ item.0 }} DELIMITER ',' CSV HEADER"
  with_together:
    - csv_file_list.stdout_lines
    - table_list.stdout_lines
  when: {{ item.1 }} != ''
Run Code Online (Sandbox Code Playgroud)

hel*_*loV 3

测试是否item.1不是无。

when: item.1 != None
Run Code Online (Sandbox Code Playgroud)