No description
Find a file
2025-08-16 13:44:47 +02:00
defaults Initial commit 2025-06-08 13:44:30 +02:00
handlers Initial commit 2025-06-08 13:44:30 +02:00
meta add namespace 2025-06-21 11:30:47 +02:00
tasks update docker install part 2025-08-16 13:44:47 +02:00
.gitignore add namespace 2025-06-21 11:30:47 +02:00
LICENSE Initial commit 2025-06-08 13:44:30 +02:00
README.md Initial commit 2025-06-08 13:44:30 +02:00

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

  1. Ensure that Ansible is installed on your system. The recommended version is at least 2.17.
  2. Clone this repository or add the role to your existing project.
  3. 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 to 3.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 up to 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:

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Submit a pull request describing your changes.

License

This project is licensed under the MIT License. For more information, see the LICENSE file.