tinyblargon.docker_deploy

Ansible Role: Docker Deployment

This Ansible role helps you set up a Docker Compose stack using a specified file.

Requirements

For Your Local Machine

  • rsync must be installed.

For the Target Machine

  • docker-ce (Docker Community Edition)
  • docker-ce-cli (Docker Command Line Interface)
  • containerd.io (Container Runtime)
  • Either docker-compose-plugin or docker-compose

Role Variables

Variable Name Type Default Value Description
docker_deploy_source: string "docker-deploy" The local folder with your Docker deployment and compose file, relevant to your main playbook directory.
docker_deploy_destination: string "/opt/docker-deploy" The folder where the deployment will be copied.
docker_deploy_compose_file: string "docker-compose.yml" The name of the Docker Compose file to use.
docker_deploy_files: list map [] A list of additional files to copy to the designated deployment folder. Further details are in the section Docker_deploy_files.
docker_deploy_compatibility: bool true Enable compatibility flag when using the compose file.
docker_deploy_remove_orphans: bool true Remove orphan containers when using the compose file.
docker_deploy_build: bool false Trigger rebuild when files in docker_deploy_source: or docker_deploy_files: have been changed.
docker_deploy_recreate: bool false Force recreate containers if files in docker_deploy_source: or docker_deploy_files: have changed.
docker_deploy_compose_plugin: bool true Choose to use the docker compose or docker-compose command, setting to true for docker compose, false for docker-compose.
docker_deploy_prune: list ["image"] Specify which prune commands to run after changes to compose deployment. It can include options like "builder", "container", "image", "network", "system", "volume".
docker_deploy_state: string "present" When set to "present", sync source to destination and bring up the compose file. When "absent", bring down the compose file from the destination.
docker_deploy_rsync_opts: list ['--exclude="*.example"'] Additional rsync options can be specified in this array. All dest files in docker_deploy_files: will be excluded from rsync automatically.
docker_deploy_show_warnings: bool true Display warnings from Docker Compose.
docker_deploy_absent_volume: bool false When state is "absent", enable volume deletion specified in the compose file.
docker_deploy_absent_remove: bool false When state is "absent" and set to true, this removes the docker_deploy_destination: folder.

Docker_deploy_files

Variable Name Type Default Value Description
content: string "" If used instead of src, sets a file's content directly. Only works when dest is a file and creates the file if it doesn’t exist.
dest: string Path on the remote server where the file will be copied. If src is a directory, dest must be a directory too. Non-existing paths are created if necessary.
group: string "root" The group that will own the file, used with chown.
mode: string Permissions for the destination file or directory. Refer to Ansible documentation for details
owner: string "root" The user that will own the file, used with chown. Avoid numeric usernames to prevent confusion.
src: string Local path to the file that needs to be copied to the remote server. Can be absolute or relative.
no_log: bool false If true, the file content won’t be logged.

If both content: and src: are empty, an empty file will be created at the destination.

Example Playbooks

Present State

- hosts: all
  roles:
    - role: tinyblargon.docker_deploy
      vars:
        docker_deploy_source: "docker-deploy"
        docker_deploy_destination: "/opt/docker-deploy"
        docker_deploy_compose_file: "docker-compose.yml"
        docker_deploy_files:
          - dest: ".env"
            src: ".env"
          - dest: ".secrets/password.txt"
            content: "{{ lookup('file', 'password.txt') }}"
            owner: "root"
            group: "root"
            mode: "0600"
            no_log: true
        docker_deploy_compatibility: true
        docker_deploy_remove_orphans: true
        docker_deploy_recreate: true
        docker_deploy_compose_plugin: false
        docker_deploy_prune: ["system"]
        docker_deploy_state: "present"

Absent State

- hosts: all
  roles:
    - role: tinyblargon.docker_deploy
      vars:
        docker_deploy_destination: "/opt/docker-deploy"
        docker_deploy_compose_file: "docker-compose.yml"
        docker_deploy_compose_plugin: false
        docker_deploy_prune: ["system", "volume"]
        docker_deploy_state: "absent"
        docker_deploy_absent_volume: true
        docker_deploy_absent_remove: true

License

MIT

Informazioni sul progetto

Ansible role to deploy a docker compose stack (file).

Installa
ansible-galaxy install tinyblargon.docker_deploy
Licenza
mit
Download
1.1k
Proprietario
If the DevOps tooling doesn't exist, I'll write it myself.