gpt4 book ai didi

docker - Ansible docker_container 模块 env 文件

转载 作者:行者123 更新时间:2023-12-02 18:15:48 25 4
gpt4 key购买 nike

我对 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"

我尝试了一个存在于 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 main\r\n cm = ContainerManager(client) File \"/tmp/ansible_rySqS2/ansible_module_docker_container.py\",
line 1668, in __init__\r\n self.parameters = TaskParameters(client)\r\n File \"/tmp/ansible_rySqS2/ansible_module_docker_container.py\",
line 784, in __init__\r\n self.env = self._get_environment()\r\n File \"/tmp/ansible_rySqS2/ansible_module_docker_container.py\",
line 1134, in _get_environment\r\n parsed_env_file = utils.parse_env_file(self.env_file)\r\n File \"/usr/lib/python2.7/site-packages/docker/utils/utils.py\",
line 961, in parse_env_file with open(env_file, 'r') as f:\r\nIOError: [Errno 2] No such file or directory: \"['/path/to/my/file/that/exist/backend-PreProd-config.env']\"\r\n", "msg": "MODULE FAILURE", "rc": 0}`

所以我的问题是,如何传递 env 文件?

最佳答案

所以我发现了问题。首先语法是:

env_file: /local/dir/some/file.env

文件必须位于目标服务器上并且第一个字符中不包含空行或空格。

关于docker - Ansible docker_container 模块 env 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44499850/

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