我想用ansible docker_container生成Influxdb配置文件。其行为与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"
当我检查输出路径/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"
register: docker
- name: display logs
debug:
msg: "{{ docker.ansible_facts.docker_container.Output }}"