状态存在,但以下所有内容都缺失:

  • 本文关键字:存在 状态 docker ansible
  • 更新时间 :
  • 英文 :


我有一个Ansible脚本来构建docker映像:

---
- hosts: localhost
tasks:
- name: build docker image
docker_image:
name: bionic
path: /
force: yes
tags: deb

和Dockerfile:

FROM ubuntu:bionic
RUN export DEBIAN_FRONTEND=noninteractive; 
apt-get -qq update && 
apt-get -qq install 
software-properties-common git curl wget openjdk-8-jre-headless debhelper devscripts
WORKDIR /workspace

:ansible-playbook build.yml -vvv我收到了下一个例外。

<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/devpc/.ansible/tmp/ansible-tmp-1633701673.999151-517949-133730725910177/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"api_version": "auto",
"archive_path": null,
"build": null,
"ca_cert": null,
"client_cert": null,
"client_key": null,
"debug": false,
"docker_host": "unix://var/run/docker.sock",
"force": true,
"force_absent": false,
"force_source": false,
"force_tag": false,
"load_path": null,
"name": "xroad-deb-bionic",
"path": "/",
"pull": null,
"push": false,
"repository": null,
"source": null,
"ssl_version": null,
"state": "present",
"tag": "latest",
"timeout": 60,
"tls": false,
"tls_hostname": null,
"use_ssh_client": false,
"validate_certs": false
}
},
"msg": "state is present but all of the following are missing: source"
}

你能给我一个提示如何调试和理解这个错误是什么意思吗?谢谢你的时间和考虑。

错误提示source:密钥必须存在于docker_image:块中

更具体地说,Ansible中的大多数东西默认为state: present。当您请求docker_image存在时,有几种方法可以获得它(从注册表中提取它,从源代码中构建它,从tar文件中解压缩它)。这种方式是由source:控件指定的,但是Ansible没有默认值。

如果您正在构建映像,则需要指定source: build。这样做之后,在build:下也有一组控件。特别是,Docker镜像上下文的路径(可能不是/)会在那里,而不是直接在docker_image:下。

剩下的内容如下:

---
- hosts: localhost
tasks:
- name: build docker image
docker_image:
name: bionic
source: build  # <-- add
build:         # <-- add
path: /home/user/src/something  # <-- move under build:
force: yes
tags: deb

最新更新