使用ansible docker_容器模块获取容器的命令输出
我想使用ansible生成XDB配置文件。 其作用与下面的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
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 }}"
我还需要更改
状态:已启动