使用docker_container模块创建容器
示例:
---
- hosts: myserverip
remote_user: root # 执行用户
gather_facts: false # 屏蔽系统信息返回
vars:
ansible_python_interpreter: /usr/bin/python3 # 定义ansible使用python3的环境
serial: "100%" # 更新比列,可以是百分比,具体数值
tasks:
- name: docker login # 登陆镜像中心
docker_login:
registry: "harbor.myregister.com"
username: "test"
password: "test"
reauthorize: yes
- name: start containerd
docker_container:
name: servername
image: imagename
hostname: servername
volumes:
- "/etc/localtime:/etc/localtime"
restart_policy: on-failure
network_mode: host # 设置网络模式
log_options: # 设置日志tag 用户elk日志采集筛选
tag: servername
capabilities:
- aLL
env: # 设置环境变量
java_opts: " -Drocketmq.client.name=servername_ip"
cpus: 2.0 # 设置cpu使用
memory: "2G" # 设置内存使用
healthcheck: # 健康检查
test: ["CMD", "curl -f http://localhost:port/actuator/health || exit 1"]
interval: "60s"
timeout: "3s"
start_period: "5s"
retries: 3
标签:container,name,servername,ansible,test,docker
From: https://www.cnblogs.com/pgyLang/p/17326588.html