如何在GitLab流水线中获取ansible-navigator日志并解决TTY错误
问题场景
GitLab流水线配置如下:
deploy-to-live: image: <custom image> # 预装有ansible-navigator stage: deploy script: >- ansible-navigator run 10_base.yml -i inventories/live
执行流水线后出现以下错误:
$ ansible-navigator run 10_base.yml -i inventories/live Running the command: docker pull <custom image>:latest the input device is not a TTY Please review the log for errors.
已知该错误由ansible-navigator自动添加的-it参数导致,且无法通过--container-options移除该参数,需要解决此错误并实现类似本地命令行的日志输出效果。
解决方法
- 使用非交互式模式运行ansible-navigator,添加
--mode stdout参数。该模式会禁用TTY交互逻辑,避免自动添加-it参数,同时直接将所有输出打印到控制台。修改后的流水线配置如下:deploy-to-live: image: <custom image> # 预装有ansible-navigator stage: deploy script: >- ansible-navigator run 10_base.yml -i inventories/live --mode stdout - 若需要查看更详细的运行日志,可额外添加
--log-level debug参数,确保所有运行细节都能在GitLab任务日志中展示:deploy-to-live: image: <custom image> # 预装有ansible-navigator stage: deploy script: >- ansible-navigator run 10_base.yml -i inventories/live --mode stdout --log-level debug - 也可通过设置环境变量
ANSIBLE_NAVIGATOR_MODE=stdout来启用非交互式模式,适合需要全局配置的场景:deploy-to-live: image: <custom image> # 预装有ansible-navigator stage: deploy variables: ANSIBLE_NAVIGATOR_MODE: stdout script: >- ansible-navigator run 10_base.yml -i inventories/live
上述修改后,ansible-navigator将以非交互式方式执行,既解决了TTY错误,又能在GitLab任务控制台中输出与本地命令行一致的日志内容。
内容的提问来源于stack exchange,提问作者Shade
相关产品推荐
相关产品推荐

