我正在使用带有 docker 插件的 jenkins 版本 2.89.1。在声明性管道阶段,我启动了一个安装了 ansible 2.4.x 的 docker 容器,以便运行一些 playbook,如下所示:
agent {
docker {
image 'myself/ansible:1.0.3'
registryUrl 'https://my-artifactory-pro'
registryCredentialsId 'my-credentials'
args '-v /var/lib/jenkins/workspace/myworkspace:/tmp/' +
' -v /var/lib/jenkins/.ssh:/root/.ssh'
}
}
steps {
echo 'Deploying Ansible Server via docker image'
sh "ansible-playbook -i /tmp/my-inventories-path/
/my-playbooks/teardown.yaml "+
"--extra-vars 'platform=ec2
aws_access_key=${AWS_ACCESS_KEY_ID}
aws_secret_key=${AWS_SECRET_ACCESS_KEY} "+
" eip_bastion_host=${EIP_BASTION_HOST}
eip_load_balancer=${EIP_LOAD_BALANCER} '"
}
管道设法旋转 docker 容器并尝试执行 ansible playbook,但我面临以下问题:
+ ansible-playbook -i /tmp/my-inventories/ /tmp/my-playbooks/teardown.yaml --extra-vars platform=ec2 aws_access_key=**** aws_secret_key=**** eip_bastion_host=X.X.X.X eip_load_balancer=X.X.X.X
[WARNING]: Unable to set correct type for configuration entry:
DEFAULT_LOCAL_TMP
PLAY [localhost] ***************************************************************
TASK [install_python_pip : Create pip folder] **********************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'getpwuid(): uid not found: 112'
fatal: [localhost]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}
to retry, use: --limit @/tmp/my-playbooks/teardown.retry
PLAY RECAP *********************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
查看 Jenkins 日志,我发现当它旋转 docker 容器时,它以下列方式启动:
docker run -t -d -u 112:116 -v /var/lib/jenkins/workspace/my-workspace --entrypoint cat myself/ansible:1.0.3
其中 112 是 jenkins uid,116 是 jenkins gid。
如果我在没有 -u 标志的情况下手动启动的同一个容器中启动相同的 ansible playbook,它可以正常工作。
那么是否可以在没有 -u 标志的情况下启动容器???为什么认为 docker 容器应该具有与 jenkins 服务器相同的 uid 和 gid ?
非常感谢马可