ci/cd roles

This commit is contained in:
CC
2026-05-21 15:56:44 +01:00
parent 223b287c08
commit 7f679b6ae2
5 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
docker_comparisons:
env: strict
labels: strict
docker_image_name_mismatch: recreate
docker_state: started
docker_restart_policy: unless-stopped
docker_pull: "missing"
gather_facts: true
config_flavor: none

View File

@@ -0,0 +1,17 @@
---
# Copy directory recursively to remote host
- name: Copy project directory to remote
ansible.builtin.synchronize:
src: ../compose/{{ folder_name }}
dest: /home/cloud/
mode: push
- name: Start Compose stack
community.docker.docker_compose_v2:
project_src: /home/cloud/{{ folder_name }}
build: always
pull: always
state: present

View File

@@ -0,0 +1,27 @@
- name: Get running containers
docker_host_info:
containers: yes
register: docker_info
- name: Stop running containers
docker_container:
name: "{{ item }}"
state: stopped
loop: "{{ docker_info.containers | map(attribute='Id') | list }}"
- name: Remove Stoped docker containers
shell: |
docker rm $(docker ps -a -q);
when: docker_info.containers != 0
- name: Get details of all images
docker_host_info:
images: yes
verbose_output: yes
register: image_info
- name: Remove all images
docker_image:
name: "{{ item }}"
state: absent
loop: "{{ image_info.images | map(attribute='Id') | list }}"

View File

@@ -0,0 +1,23 @@
- name: Install gpg
ansible.builtin.apt:
name: gpg
- name: Add Docker repository key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg
keyring: /etc/apt/trusted.gpg.d/docker.gpg
- name: Add Docker repository
ansible.builtin.apt_repository:
# Use HTTP to enable apt-cacher
repo: deb http://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable
filename: docker
- name: Install Docker
ansible.builtin.apt:
name: "{{ item }}"
loop:
- docker-ce
- docker-ce-cli
- containerd.io

View File

@@ -0,0 +1,17 @@
---
- name: Docker Install
include_tasks: docker_install.yml
when: config_flavor == "install"
- name: Docker Stop & Destroy
include_tasks: docker_destroy.yml
when: config_flavor == "destroy"
- name: Docker Transfer Compose to Remote Host
include_tasks: docker_copy.yml
when: config_flavor == "copy"
#####
# You need to set up each docker playbook to a config flavor or look for an input module and assign config_flavor to it
######