Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ansible docker_容器模块获取容器的命令输出_Ansible - Fatal编程技术网

使用ansible docker_容器模块获取容器的命令输出

使用ansible docker_容器模块获取容器的命令输出,ansible,Ansible,我想使用ansible生成XDB配置文件。 其作用与下面的docker命令相同 docker run--rm influxdb influxd config>/opt/influxdb/config/influxdb.conf 我在我的剧本上创建了一个任务,如下所示 - name: generate influxdb config using temporary container docker_container: name: influxdb_conf s

我想使用ansible生成XDB配置文件。 其作用与下面的docker命令相同

docker run--rm influxdb influxd config>/opt/influxdb/config/influxdb.conf

我在我的剧本上创建了一个任务,如下所示

  - name: generate influxdb config using temporary container
    docker_container:
      name: influxdb_conf
      state: present
      image: influxdb:1.4
      command: influxd config > /tmp/influxdb.conf
      volumes:
        - "/opt/influxdb/config:/tmp"
- name: generate influxdb config using temporary container
  docker_container:
    name: influxdb_conf
    state: present
    image: influxdb:1.4
    command: influxd config > /tmp/influxdb.conf
    volumes:
      - "/opt/influxdb/config:/tmp"
  register: docker

- name: display logs
  debug:
    msg:  "{{ docker.ansible_facts.docker_container.Output }}"
当我检查输出路径
/opt/influxdb/config
时,它是空的。
如何获取
influxd config
输出?

您可以执行
/bin/sh
作为命令,也可以使用
detach
cleanup

  - name: generate influxdb config using temporary container
    docker_container:
      name: influxdb_conf
      state: started
      image: influxdb:1.4
      command: "/bin/sh -c 'influxd config > /tmp/influxdb.conf'"
      detach: no
      interactive: yes
      tty: yes
      recreate: yes
      cleanup: yes
      volumes:
        - /opt/influxdb/config:/tmp

您可以注册模块并使用ansible_facts在下一个任务中获取日志,如下所示

  - name: generate influxdb config using temporary container
    docker_container:
      name: influxdb_conf
      state: present
      image: influxdb:1.4
      command: influxd config > /tmp/influxdb.conf
      volumes:
        - "/opt/influxdb/config:/tmp"
- name: generate influxdb config using temporary container
  docker_container:
    name: influxdb_conf
    state: present
    image: influxdb:1.4
    command: influxd config > /tmp/influxdb.conf
    volumes:
      - "/opt/influxdb/config:/tmp"
  register: docker

- name: display logs
  debug:
    msg:  "{{ docker.ansible_facts.docker_container.Output }}"

我还需要更改
状态:已启动