bash - 带有for循环的ansible剧本没有按预期工作
问题描述
尝试创建一个剧本来检查 docker 容器日志,但它不会遍历 for 循环
- hosts: all
become: yes
gather_facts: no
tasks:
- name: Check container logs
shell: |
for i in "web_container_node{1..5}"; do
echo ""
echo "#### ${i} ####"
echo ""
docker logs --tail 10 ${i}
done
args:
executable: /bin/bash
但是输出在没有迭代的情况下直接传递了剧本中的容器名称
No such container: "web_container_node{1..5}",
解决方案
您使用 bash 扩展的方式不起作用,即使在 bash 中,我建议您这样做。
- name: Check container logs
shell: |
for i in {1..5}; do
echo "webcontainer${i}"
echo ""
echo "#### ${i} ####"
echo ""
docker logs --tail 10 ${i}
done
args:
executable: /bin/bash
推荐阅读
- python - 如何以编程方式修改 Windows 上的 iTunes 播放列表?
- nutch - Nutch Fetch 失败,协议状态为:moved(12),lastModified=0:https://moorecompletedental.com/
- weblogic12c - wlst 离线将用户添加到现有域
- spring-boot - 当对象的默认生命周期为单例时,SpringBoot 中的并发如何工作
- android - 没有写入文件的权限:///storage/9016-4EF8:用户 10390 和当前进程都没有 android.permission.WRITE_MEDIA_STORAGE
- javascript - 在调用 Angular 构造函数之前捕获查询字符串
- centos - 错误 Dockerfile 返回一个非零代码:127
- r - 如何将 wiki 标记转换为文本?R/维基百科
- php - php - ldap 组导出到 csv
- swift - 快速将Base64字符串转换为音频文件