| defaults | ||
| handlers | ||
| meta | ||
| tasks | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
docker_compose_up Role
This role manages the deployment and execution of Docker Compose projects. It ensures that Docker and Docker Compose are installed, the required Compose files are present, and the specified services are started and running.
Description
The docker_compose_up role simplifies the process of managing Docker Compose projects. It ensures that Docker and Docker Compose are installed, copies the required Compose files to the target system, and runs docker-compose up to start the services. Additionally, it provides cleanup functionality to remove unused Docker resources.
Installation
- Ensure that Ansible is installed on your system. The recommended version is at least
2.17. - Clone this repository or add the role to your existing project.
- Install the required Ansible collection:
ansible-galaxy collection install community.docker
Variables
The role uses the following variables to configure Docker Compose projects:
Docker Variables
-
docker_compose_up_compose_files: A list of dictionaries defining the source and destination of Docker Compose files. Each dictionary includes:src: The local path to the Compose file. Example:files/docker-compose.yml.dest: The destination path on the target system. Example:/opt/docker_folder/docker-compose.yml.
-
docker_compose_up_python_version: The Python version to use for installing required packages. Defaults to3.11. -
docker_compose_up_python_modules: A list of Python modules to install. Defaults to:docker_compose_up_python_modules: - requests
Usage
Example Playbook
- name: Deploy Docker Compose Project
hosts: all
become: true
vars:
docker_compose_up_compose_files:
- src: files/docker-compose.yml
dest: /opt/docker_folder/docker-compose.yml
- src: files/docker-compose.override.yml
dest: /opt/docker_folder/docker-compose.override.yml
roles:
- role: docker_compose_up
Features
- Docker and Docker Compose Installation: Ensures Docker and Docker Compose are installed on the target system.
- Dynamic Docker Compose File Management: Copies Compose files from the control node to the target system.
- Environment Variable Support: Allows passing environment variables to Docker Compose.
- Service Management: Runs
docker-compose upto start the services defined in the Compose files. - Cleanup Functionality: Prunes unused Docker resources to free up space.
- Support for Multiple Compose Files: Supports overriding default Compose configurations with additional files.
Handlers
The role includes the following handlers:
- Prune unused Docker resources: Cleans up unused Docker containers, images, networks, and volumes.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Submit a pull request describing your changes.
License
This project is licensed under the MIT License. For more information, see the LICENSE file.