From 471f08bd3ad334d04dc7b130c973f60d485b2ea8 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Mon, 28 Apr 2025 10:32:32 +0800 Subject: [PATCH] =?UTF-8?q?build(ansible):=20=E6=B7=BB=E5=8A=A0env.cfg?= =?UTF-8?q?=E5=92=8Cdocker-compose.yml=E6=96=87=E4=BB=B6=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加env.cfg文件用于配置镜像标签,docker-compose.yml文件用于定义Ansible服务容器。更新dockerfile以优化依赖安装和容器入口点配置,确保容器运行更高效和安全。 --- ansible/docker-compose.yml | 19 +++++++++++++++++++ ansible/dockerfile | 12 +++++++----- ansible/env.cfg | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 ansible/docker-compose.yml create mode 100644 ansible/env.cfg diff --git a/ansible/docker-compose.yml b/ansible/docker-compose.yml new file mode 100644 index 0000000..8141409 --- /dev/null +++ b/ansible/docker-compose.yml @@ -0,0 +1,19 @@ +# DEPLOY:: docker compose -p base --env-file ./ansible/env.cfg -f ./ansible/docker-compose.yml up -d +services: + ansible: + image: ${IMAGE_TAG} + volumes: + - ~/.ssh:/home/ansible-user/.ssh + - ./ansible.cfg:/etc/ansible/ansible.cfg + - ./ansible_hosts:/etc/ansible/hosts + - ~/playbooks:/home/ansible-user/playbooks + environment: + - ANSIBLE_HOST_KEY_CHECKING=False + tty: true + stdin_open: true + networks: + - ansible-net + +networks: + ansible-net: + driver: bridge \ No newline at end of file diff --git a/ansible/dockerfile b/ansible/dockerfile index ae686a7..a145733 100644 --- a/ansible/dockerfile +++ b/ansible/dockerfile @@ -1,19 +1,21 @@ +# BUILD:: docker buildx build --platform linux/amd64 -t hub.tp229.com:3500/ansible-alpine:py3.13-rootless . FROM python:3.13.3-alpine # 使用国内镜像源 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories # 安装必要的依赖 -RUN apk add --no-cache \ +RUN apk add --update --no-cache \ openssh-client \ sshpass \ + bash \ git \ rsync # 安装Ansible及相关工具 RUN pip install --no-cache-dir \ + -i https://mirrors.ustc.edu.cn/pypi/simple \ ansible \ - ansible-lint \ - jmespath + ansible-lint # 创建非root用户(安全建议) RUN adduser -D ansible-user @@ -21,5 +23,5 @@ USER ansible-user WORKDIR /home/ansible-user # 入口点配置 -ENTRYPOINT ["ansible"] -CMD ["--version"] \ No newline at end of file +ENTRYPOINT [] +CMD ["ansible", "--version"] \ No newline at end of file diff --git a/ansible/env.cfg b/ansible/env.cfg new file mode 100644 index 0000000..a3c8af7 --- /dev/null +++ b/ansible/env.cfg @@ -0,0 +1 @@ +IMAGE_TAG=hub.tp229.com:3500/ansible-alpine:py3.13-rootless \ No newline at end of file