我对ansible(v2.3)的docker_container模块有一个问题。当我尝试在playbook中传递env_file属性时,我得到错误:没有这样的文件或目录。
---
- 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 serveur上的文件和目标服务器上的文件,但结果相同。
这是错误:
`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文件?
答案 0 :(得分:1)
所以我发现了问题。 首先语法是:
env_file: /local/dir/some/file.env
该文件必须位于目标服务器上,并且在第一个字符中不包含空行或空格。
答案 1 :(得分:0)
env_file
必须是您的主机的本地,而不是容器内的文件。
env_file:
- "/local/dir/some/file.env"
答案 2 :(得分:0)
在接受的答案中添加一些有用的信息。
这里是如何编写环境变量文件。
USER=ElonMusk
PASSWORD=EV
DATABASE=Tesla