我有一个Ansible repo与以下目录路径
.
├── kube-init.sh
├── provisioning
│ ├── group_vars
│ │ └── all.yml
│ ├── roles
│ │ └── app_deploy
│ │ ├── files
│ │ │ ├── secretfile
│ │ ├── tasks
│ │ │ ├── docker
│ │ │ │ ├── Dockerfile
│ │ │ └── main.yml
│ │ └── vars
│ │ └── main.yaml
│ └── site.yml
├── README.md
我试图在provisioning/roles/app_deploy/tasks/main.yaml
定义一个docker构建映像任务,如下所示
- name: Build image and with build args
vars:
ansible_python_interpreter: /usr/bin/python3
docker_image:
name: app-name
build:
path: docker
dockerfile: Dockerfile
args:
log_volume: /var/log/svm
listen_port: 8080
state: present
source: build
我不能得到Dockerfile/context提供给可见的任务。path
和dockerfile
组合的相对/绝对值的各种组合。
我认为最明显的选择是跳过使用dockerfile
,只是使用path
作为./docker
,这并没有使我感到惊讶。
在Python3和Docker SDK版本5以上使用Ansible
多一点上下文。我实际上使用Vagrant与Openstack插件来配置我的Ansible任务的新计算。插件将repo (Ansible)的内容复制到路径/home/vagrant
的目标机器上,并从那里运行配置脚本。
我找到了正确的路径,通过以下方式为docker模块。我在下面添加了一个调试任务,以找出app_deploy/tasks/main.yml
作为
- name: Find out playbook's path
shell: pwd
register: playbook_path_output
- debug: var=playbook_path_output.stdout
返回provisioning/roles
。我意识到路径是从site.yml
所在的位置,它定义了一个角色为app_deploy
。
- name: Build image and with build args
vars:
ansible_python_interpreter: /usr/bin/python3
docker_image:
name: app-name
build:
path: ./roles/app_deploy/tasks/docker/
args:
log_volume: /var/log/svm
listen_port: 8080
state: present
source: build
但是根据Zeitounator的评论,上面可能不是将Dockerfile及其组成文件存储在特定角色目录中的正确做法。