Is there any way to run official hashicorp/consul docker image with ansible docker_container module? All i can do is run it in development mode, which is default. Seems it can’t pass arguments to docker, most important one being “-server”. I have tried with env variables like CONSUL_SERVER, CONSULE_SERVER_MODE, CONSUL_AGENT_MODE adn with command executed after but nothing seems to work.
Has anyone made it work?
Hi @algavran,
Welcome to the HashiCorp Forums!
You have to make sure that the command starts with agent
as explained in here: Docker
Here is a sample playbook that I used to run a single node Consul using the docker_container
module with host
mode networking.
#file: consul.yaml
---
- hosts: localhost
become: true
connection: local
tasks:
- name: run docker consul
docker_container:
name: consul
image: hashicorp/consul
command:
- agent
- -server
- -bootstrap-expect=1
network_mode: host
env:
CONSUL_BIND_INTERFACE: eth0
Here is a demo of this working: Ansible Consul using docker_container module - asciinema.org
I hope this helps!
Thank you @Ranjandas , it work with passing arguments with command