Reputation: 147
I have an issue with the docker_container module for ansible (v2.3). When i try to pass the env_file
properties in the playbook, I get the error :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"
I have tried with a file that exist on the ansible server and one on the target server with the same result.
here is the error :
`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}`
So my question is, how can I pass the env file ?
Upvotes: 3
Views: 5980
Reputation: 4634
To add some useful information to the accepted answer.
Here is how you can write environment variable file.
USER=ElonMusk
PASSWORD=EV
DATABASE=Tesla
Upvotes: 0
Reputation: 147
so i found the problem. first the syntax is :
env_file: /local/dir/some/file.env
the file must be located on the target server and contain NO blank line or spaces in the first character.
Upvotes: 5
Reputation: 36733
The env_file
must be local to your host, and not a file inside the container.
env_file:
- "/local/dir/some/file.env"
Upvotes: 1