add collections

This commit is contained in:
Gary Kwok
2024-02-01 11:40:42 +08:00
parent 0715d7c475
commit 7af4c56c96
3198 changed files with 455118 additions and 0 deletions

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