################################################# # DO Community Playbooks: Docker ################################################# --- - hosts: all become: true vars_files: - vars/default.yml tasks: - name: Pull Wordpress image docker_image: name: "{{ image_name }}" source: pull force_source: yes - name: Copy dockerfile synchronize: src=web dest=/tmp - name: Build nginx webserver image docker_image: name: wordpress-web build: path: /tmp/web/ dockerfile: /tmp/web/Dockerfile pull: yes state: present source: build - name: Create Wordpress container docker_container: name: "{{ container_name }}" image: "{{ image_name }}" state: started restart_policy: "unless-stopped" env: WORDPRESS_DB_HOST: "{{ db_host }}" WORDPRESS_DB_USER: "{{ db_user }}" WORDPRESS_DB_PASSWORD: "{{ db_pass }}" WORDPRESS_DB_NAME: "{{ db_name }}" volumes: - "/var/lib/{{ http_host }}:/var/www/html" - name: Create webserver container docker_container: name: wp-web image: wordpress-web state: started restart_policy: "unless-stopped" links: - "{{ container_name }}:wordpress" published_ports: - "127.0.0.1:{{ web_port }}:80" volumes: - "/var/lib/{{ http_host }}:/var/www/html" # - name: Check if Nginx conf file exists # stat: path="/etc/nginx/sites-available/{{ http_conf }}" # register: status # - name: No need to reload Nginx # debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }} - name: Set Nginx conf file # when: status.stat.exists == false template: src: "files/nginx.conf-ff.j2" dest: "/etc/nginx/sites-available/{{ http_conf }}" - name: Enable new site # when: status.stat.exists == false file: src: "/etc/nginx/sites-available/{{ http_conf }}" dest: "/etc/nginx/sites-enabled/{{ http_conf }}" state: link notify: Reload Nginx handlers: - name: Reload Nginx service: name: nginx state: reloaded