我对 ansible (v2.3) 的 docker_container 模块有疑问。当我尝试传递env_file剧本中的属性时,出现错误:no such file or directory
---
- hosts: preprod-api
become: yes
gather_facts: true
tasks:
- name: test configuration
docker_container:
name: "backend"
image: "backend"
state: started
exposed_ports:
- 80
volumes:
- /opt/application/i99/current/logs
user: ansible
env_file:
- "/opt/application/i99/current/backend/backend-PreProd-config.list"
Run Code Online (Sandbox Code Playgroud)
我尝试使用 ansible 服务器上存在的一个文件和目标服务器上存在的一个文件,得到相同的结果。
这是错误:
`fatal: [my_hostname]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to my_hostname closed.\r\n",
"module_stdout": "Traceback (most recent call last):
File \"/tmp/ansible_rySqS2/ansible_module_docker_container.py\",
line 2036, in <module> main() File \"/tmp/ansible_rySqS2/ansible_module_docker_container.py\",
line 2029, in …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的字符串变量RCD_APIS=backend,api-alerting,api-tracking,api-versioning,其中包含我的泊坞窗图像的名称。我需要将它分成一个数组并循环它,这样我就可以提取每个泊坞窗图像
我尝试过 with_sequence 循环,但我只得到索引 (1,2,3,..)
- name: pull images from registry
docker_image:
name: "hostname:5000/{{ RCD_APIS.split(',') }}"
pull: true
state: present
tag: "{{RCD_VERSION_CURRENT}}"
with_sequence: count={{ RCD_APIS|count }}
Run Code Online (Sandbox Code Playgroud)
我也尝试过 with_item 循环,但它不起作用,所以我尝试调试:
vars:
- container: "{{ RCD_APIS }}"
tasks:
- name: pull images from registry debug
debug: var={{item|basename}}
with_items: container.split(',')
Run Code Online (Sandbox Code Playgroud)
我得到类似的东西:
(item=container.split(',')) => {
"container.split(',')": [
"backend",
"api-alerting",
"api-tracking",
"api-versioning",
"connecteur-gdfa",
"api-batch",
"ihm"
],
"item": "container.split(',')"
}
Run Code Online (Sandbox Code Playgroud)
那么我如何循环该数组(如 foreach)并执行docker pull backend, docker pull api-alerting...?