gpt4 book ai didi

jenkins - 无法通过 docker 容器执行 ansible playbook

转载 作者:IT老高 更新时间:2023-10-28 21:40:44 27 4
gpt4 key购买 nike

我正在 docker 容器内的 jenkins 上执行管道。此管道调用另一个执行 ansible playbook 的 docker-compose 文件。执行 playbook 的服务称为代理,定义如下:

agent:
image: pjestrada/ansible
links:
- db
environment:
PROBE_HOST: "db"
PROBE_PORT: "3306"
command: ["probe.yml"]

这是它使用的图像:

FROM ubuntu:trusty
MAINTAINER Pablo Estrada <pjestradac@gmail.com>

# Prevent dpkg errors
ENV TERM=x-term-256color


RUN sed -i "s/http:\/\/archive./http:\/\/nz.archive./g" /etc/apt/sources.list


#Install ansible

RUN apt-get update -qy && \
apt-get install -qy software-properties-common && \
apt-add-repository -y ppa:ansible/ansible && \
apt-get update -qy && \
apt-get install -qy ansible

# Copy baked in playbooks

COPY ansible /ansible

# Add voulme for Ansible Playbooks
Volume /ansible
WORKDIR /ansible
RUN chmod +x /
#Entrypoint
ENTRYPOINT ["ansible-playbook"]
CMD ["site.yml"]

我的本​​地机器是 Ubuntu 16.04,当我运行 docker-compose up agent plabook 成功执行。但是,当我在 jenkins 容器中时,我在同一个命令调用中收到此错误。

Attaching to todobackend9dev_agent_1
[36magent_1 | [0mERROR! the playbook: site.yml does not appear to be a file

这是我的 Jenkins 容器的图像和撰写文件:

FROM jenkins:1.642.1
MAINTAINER Pablo Estrada <pjestradac@gmail.com>

# Suppress apt installation warnings
ENV DEBIAN_FRONTEND=noninteractive

# Change to root user
USER root

# Used to set the docker group ID
# Set to 497 by default, which is the group ID used by AWS Linux ECS Instance
ARG DOCKER_GID=497

# Create Docker Group with GID
# Set default value of 497 if DOCKER_GID set to blank string by Docker Compose
RUN groupadd -g ${DOCKER_GID:-497} docker

# Used to control Docker and Docker Compose versions installed
# NOTE: As of February 2016, AWS Linux ECS only supports Docker 1.9.1
ARG DOCKER_ENGINE=1.10.2
ARG DOCKER_COMPOSE=1.6.2

# Install base packages
RUN apt-get update -y && \
apt-get install apt-transport-https curl python-dev python-setuptools gcc make libssl-dev -y && \
easy_install pip

# Install Docker Engine
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D && \
echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | tee /etc/apt/sources.list.d/docker.list && \
apt-get update -y && \
apt-get purge lxc-docker* -y && \
apt-get install docker-engine=${DOCKER_ENGINE:-1.10.2}-0~trusty -y && \
usermod -aG docker jenkins && \
usermod -aG users jenkins

# Install Docker Compose
RUN pip install docker-compose==${DOCKER_COMPOSE:-1.6.2} && \
pip install ansible boto boto3

# Change to jenkins user
USER jenkins


# Add Jenkins plugins
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt

编写文件:

version: '2'

volumes:
jenkins_home:
external: true

services:
jenkins:
build:
context: .
args:
DOCKER_GID: ${DOCKER_GID}
DOCKER_ENGINE: ${DOCKER_ENGINE}
DOCKER_COMPOSE: ${DOCKER_COMPOSE}
volumes:
- jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "8080:8080"

我放了一个卷以便从我的 jenkins 容器中访问 docker 套接字。但是,由于某种原因,我无法访问我需要的 playbook 的 site.yml 文件,即使在容器之外该文件可用。

谁能帮我解决这个问题?

最佳答案

您对该卷安装点和路径的确定程度如何?

- jenkins_home:/var/jenkins_home

您是否尝试过通过 echo 进行调试?如果找不到 site.yml,则最可能的原因是路径。您可以在作业上使用 jenkins replay 来快速迭代并修改部分 jenkins 代码。这会让你运行类似的东西

sh "pwd; ls -la"

我建议在您的 docker 容器中添加等效项,以便您检查路径。我的猜测是工作空间不是你想的那样,你会想用以下方式运行 docker:

-v${env.WORKSPACE}:jenkins-workspace

然后在容器内:

pushd /jenkins-worspace

关于jenkins - 无法通过 docker 容器执行 ansible playbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39565376/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com