gpt4 book ai didi

ansible - ansible with_together 中的复杂循环

转载 作者:行者123 更新时间:2023-12-03 17:05:52 24 4
gpt4 key购买 nike

如果我使用 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 }} != ''

最佳答案

测试是否 item.1不是没有。

when: item.1 != None

关于ansible - ansible with_together 中的复杂循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35605921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com