Hi,
I’ve create an ansible project which uses “docker_compose” to compose my docker-compose.yml file present in the following directory.
[root@jyothishvv tasks]# cat docker-compose.yml
version: “3”
services:
webserver:
build:
context: ./DF
container_name: “{WEBSERVER_HTTP_CONTAINER_APPNAME}"
restart: 'always'
ports:
- "{WEBSERVER_HTTP_CONTAINER_PORT1}:80”
- “{WEBSERVER_HTTP_CONTAINER_PORT2}:443"
volumes:
- "/opt/shared/{WEBSERVER_HTTP_CONTAINER_USERNAME}/public_html:/var/www/html”
- “/opt/shared/{WEBSERVER_HTTP_CONTAINER_USERNAME}/php/php.ini:/usr/local/etc/php/php.ini"
- "/opt/shared/{WEBSERVER_HTTP_CONTAINER_USERNAME}/vhosts:/etc/apache2/sites-enabled”
- “/opt/shared/${WEBSERVER_HTTP_CONTAINER_USERNAME}/logs:/var/log/apache2”
Also, my docker ansible-playbook is given below.
[root@jyothishvv tasks]# cat main.yml
- name : Run docker-compose using ansible
docker_compose:
project_src: /opt/playbook/hosting/roles/webserver/tasks
state: present
I have created an environment file with following content.
[root@jyothishvv hosting]# cat env.sh
#!/bin/bash
export WEBSERVER_HTTP_CONTAINER_USERNAME=lmdapp1usr
export WEBSERVER_HTTP_CONTAINER_APPNAME=lmdapp1
export WEBSERVER_HTTP_CONTAINER_PORT1=2000
export WEBSERVER_HTTP_CONTAINER_PORT2=2043
export DBSERVER_MYSQL_CONTAINER_PORT1=3000
export CACHESERVER_REDIS_CONTAINER_PORT1=6000
export DBSERVER_MYSQLMGMT_CONTAINER_PORT1=8000
During the first time when I run this ansible-playbook using this docker-compose file the following docker instances were created succesfully.
[root@jyothishvv hosting]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8305621908a2 redis:latest “docker-entrypoint.s…” 18 minutes ago Up 18 minutes 0.0.0.0:6000->6379/tcp lmdapp1_redis
88701e279616 phpmyadmin/phpmyadmin “/docker-entrypoint.…” 18 minutes ago Up 18 minutes 0.0.0.0:8000->80/tcp lmdapp1_phpmyadmin
9d236b427647 mysql:5.6.44 “docker-entrypoint.s…” 18 minutes ago Up 18 minutes 0.0.0.0:3000->3306/tcp lmdapp1_mysql_5.6
96b47df264e3 tasks_webserver “/usr/sbin/apache2ct…” 18 minutes ago Up 18 minutes 0.0.0.0:2000->80/tcp, 0.0.0.0:2043->443/tcp lmdapp1
But while I changed the env.sh details as follows and executing ansible-playbook, instead of creating new docker instances along with old instances, it is deleting all the old ones and creating new one.
changed env.sh is given below:
[root@jyothishvv hosting]# cat env.sh
#!/bin/bash
export WEBSERVER_HTTP_CONTAINER_USERNAME=lmdapp2usr
export WEBSERVER_HTTP_CONTAINER_APPNAME=lmdapp2
export WEBSERVER_HTTP_CONTAINER_PORT1=2001
export WEBSERVER_HTTP_CONTAINER_PORT2=2044
export DBSERVER_MYSQL_CONTAINER_PORT1=3001
export CACHESERVER_REDIS_CONTAINER_PORT1=6001
export DBSERVER_MYSQLMGMT_CONTAINER_PORT1=8001
Can any body address my problem. If you are not clear about the issue, please let me know.