This commit is contained in:
Gary Kwok
2024-02-20 17:54:16 +08:00
parent dbeaa3fc54
commit 8674b4dfde
3199 changed files with 455120 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
- hosts: localhost
vars:
docker_test_image_alpine: quay.io/ansible/docker-test-containers:alpine3.8
tasks:
- name: Find all roles
find:
paths:
- "{{ (playbook_dir | default('.')) ~ '/roles' }}"
file_type: directory
depth: 1
register: result
- name: Include all roles
include_role:
name: "{{ item }}"
loop: "{{ result.files | map(attribute='path') | map('regex_replace', '.*/', '') | sort }}"

View File

@@ -0,0 +1,28 @@
---
- name: Retrieve information on current container
community.docker.current_container_facts:
register: result
# The following two tasks are useful if we ever have to debug why this fails.
- name: Print all Ansible facts
debug:
var: ansible_facts
- name: Read some files
slurp:
src: "{{ item }}"
loop:
- /proc/self/cpuset
- /proc/1/cgroup
- /proc/1/environ
- name: Print facts returned by module
debug:
var: result.ansible_facts
- name: Validate results
assert:
that:
- ansible_module_running_in_container
- ansible_module_container_type != ''

View File

@@ -0,0 +1,34 @@
---
# Create random name prefix (for containers, networks, ...)
- name: Create random container name prefix
set_fact:
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Create project and container names
set_fact:
pname: "{{ cname_prefix }}"
cname: "{{ cname_prefix }}-hi"
- name: Define service
set_fact:
test_service: |
version: '3'
services:
{{ cname }}:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
stop_grace_period: 1s
- name: Present
community.docker.docker_compose:
project_name: "{{ pname }}"
state: present
remove_orphans: true
definition: "{{ test_service | from_yaml }}"
- name: Absent
community.docker.docker_compose:
project_name: "{{ pname }}"
state: absent
remove_orphans: true
definition: "{{ test_service | from_yaml }}"

View File

@@ -0,0 +1,28 @@
---
# Create random name prefix (for containers, networks, ...)
- name: Create random container name prefix
set_fact:
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
- name: Make sure image is absent
community.docker.docker_image:
name: "{{ docker_test_image_alpine }}"
state: absent
- name: Make sure image is pulled
community.docker.docker_image:
name: "{{ docker_test_image_alpine }}"
source: pull
- name: Start container
community.docker.docker_container:
name: "{{ cname_prefix }}-1"
image: "{{ docker_test_image_alpine }}"
state: started
- name: Remove container
community.docker.docker_container:
name: "{{ cname_prefix }}-1"
state: absent
stop_timeout: 1
force_kill: yes

View File

@@ -0,0 +1,2 @@
---
# Currently the docker_stack* modules are not supported in the EE since we'd need to install the Docker CLI client