docker-compose和ansible中的“mount if not exist”子句

我定义了几个path,我应该在哪里find一个安全的词典:

"/data/athena/jenkins_master/home/logs" "/data/athena/jenkins_master/home/logs/*" "/data/athena/jenkins_master/home/logs/*/*" "/data/athena/jenkins_master/home/jobs/*/builds/*" 

然后,在docker-compose中,我想挂载所有的相对卷,但是因为我在path中有recursion信息,所以决定挂载父目录。

泊坞窗,compose.yml

 {% for log in in_filebeat_dict.filebeat.logs | default([]) %} - {{ log.path.split('*')[0] }}:{{ log.path.split('*')[0] }}:ro {% endfor %} 

现在我的问题是,对于所有这些条目,它将尝试挂载几次: "/data/athena/jenkins_master/home/logs" ,并将失败

当我在另一部分(filebeat)中使用它时,我必须保留在词典中的细节。

我想知道如何在docker-compose中包含“挂载如果不存在”子句

我应该如何实现它?

您可以在循环之前应用检查唯一性:

 {% for log_path in in_filebeat_dict.filebeat.logs | default([]) | map(attribute='path') | map('regex_search','^([^*]+$|.*?(?=/[*]))') | list | unique %} - {{ log_path }}:{{ log_path }}:ro {% endfor %} 

正则expression式^([^*]+$|.*?(?=/[*]))是select不带*的path或带有/*的path的第一部分。

    Interesting Posts