Ansible对Docker容器或卷执行命令Shell Bash

时间:2019-03-18 17:42:02

标签: bash docker ansible kapacitor

我假装用ansible在docker容器内执行bash文件。解雇任务是成功的。

我的任务:

- name: Copy tickscripts
  copy:
    src: /home/debian/github/tick_playbook/roles/alertas
    dest: /var/lib/docker/volumes/kapacitor_storage/_data/

- name: Execute tickscripts
  shell: bash /var/lib/docker/volumes/kapacitor_storage/_data/alertas/run_alertas.sh

容器名称:tick_kapacitor 体积容器:kapaciotr_sotage

运行剧本,完成一项任务

root@teste:/# cat /var/lib/docker/volumes/kapacitor_storage/_data/alertas/

 run_alertas.sh  tasks/          tickscripts/

root@teste:/# cat /var/lib/docker/volumes/kapacitor_storage/_data/alertas/

我也尝试:

  - name: Execute tickscripts
  shell: docker exec -ti tick_kapacitor /bin/bash var/lib/kapacitor/alertas/run_alertas.sh

响应:

TASK [alertas : Execute tickscripts] *******************************************
fatal: [192.168.85.79]: FAILED! => {"changed": true, "cmd": "docker exec -ti tick_kapacitor /bin/bash var/lib/kapacitor/alertas/run_alertas.sh", "delta": "0:00:00.043861", "end": "2019-03-18 17:52:50.542327", "failed": true, "rc": 1, "start": "2019-03-18 17:52:50.498466", "stderr": "the input device is not a TTY", "stdout": "", "stdout_lines": [], "warnings": []}
        to retry, use: --limit @/home/debian/github/tick_playbook/teste.retry

我去机器上放

  docker exec -ti tick_kapacitor /bin/bash var/lib/kapacitor/alertas/run_alertas.sh

响应:

var/lib/kapacitor/alertas/tickscripts/cpu99_alert_stream.tick

1 个答案:

答案 0 :(得分:0)

从您的shell命令中删除-ti标志。

它用于启动持续的交互式会话-在运行Ansible播放时您都不感兴趣。