$ ansible --version && molecule --version
ansible 2.7.8
config file = None
configured module search path = [u'/Users/tomasz/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Users/tomasz/Library/Python/2.7/lib/python/site-packages/ansible
executable location = /Users/tomasz/Library/Python/2.7/bin/ansible
python version = 2.7.15 (default, Feb 12 2019, 12:27:02) [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]
molecule, version 2.19.0
Molecule installation method:
Ansible installation method:
Detail any linters or test runners used:
I'm trying to configure symlinks to inventory file (hosts), group_vars and host_vars of my prod environment:
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: instance1
image: ubuntu:18.04
groups:
- haproxy-group
- name: instance2
image: ubuntu:18.04
groups:
- haproxy-group
provisioner:
name: ansible
log: true
inventory:
links:
hosts: ../../../../env/live/inventory/hosts
group_vars: ../../../../env/live/inventory/group_vars
host_vars: ../../../../env/live/inventory/host_vars
env:
ANSIBLE_ROLES_PATH: ../../../../roles/
playbooks:
converge: ../../haproxy.yml
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
$ molecule --debug converge
--> Validating schema /Users/tomasz/ansible-playbooks/haproxy/molecule/default/molecule.yml.
Validation completed successfully.
--> Test matrix
└── default
├── dependency
├── create
├── prepare
└── converge
--> Inventory /Users/tomasz/ansible-playbooks/haproxy/molecule/default/../../../../env/live/inventory/group_vars linked to /var/folders/1r/bt9yc5vd7fd0k8sqvw73xs900000gn/T/molecule/haproxy/default/group_vars
--> Inventory /Users/tomasz/ansible-playbooks/haproxy/molecule/default/../../../../env/live/inventory/hosts linked to /var/folders/1r/bt9yc5vd7fd0k8sqvw73xs900000gn/T/molecule/haproxy/default/hosts
Traceback (most recent call last):
File "/Users/tomasz/Library/Python/2.7/bin/molecule", line 10, in <module>
sys.exit(main())
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/molecule/command/converge.py", line 112, in converge
base.execute_subcommand(scenario.config, action)
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/molecule/command/base.py", line 100, in execute_subcommand
return command(config).execute()
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/molecule/command/base.py", line 51, in __init__
self._setup()
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/molecule/command/base.py", line 93, in _setup
self._config.provisioner.manage_inventory()
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/molecule/provisioner/ansible.py", line 633, in manage_inventory
self._link_or_update_vars()
File "/Users/tomasz/Library/Python/2.7/lib/python/site-packages/molecule/provisioner/ansible.py", line 718, in _link_or_update_vars
os.symlink(source, target)
OSError: [Errno 17] File exists
````
However, the symlink is actually created in $MOLECULE_EPHEMERAL_DIRECTORY:
$ ll $MOLECULE_EPHEMERAL_DIRECTORY
total 32
-rw-r--r-- 1 tomasz staff 151B Mar 18 11:00 Dockerfile_ubuntu_18_04
-rw-r--r-- 1 tomasz staff 239B Mar 18 11:03 ansible.cfg
-rw-r--r-- 1 tomasz staff 713B Mar 18 11:03 ansible_inventory.yml
lrwxr-xr-x 1 tomasz staff 117B Mar 18 11:03 group_vars -> /Users/tomasz/ansible-playbooks/haproxy/molecule/default/../../../../env/live/inventory/group_vars
lrwxr-xr-x 1 tomasz staff 112B Mar 18 11:02 hosts -> /Users/tomasz/ansible-playbooks/haproxy/molecule/default/../../../../env/live/inventory/hosts
-rw-r--r-- 1 tomasz staff 85B Mar 18 11:03 state.yml
Everything works fine when I comment out:
hosts: ../../../../env/live/inventory/hosts
```
Thanks for the report @TomaszKlosinski!
Looks like something related to the recent https://github.com/ansible/molecule/pull/1774.
cc @beenje
One more interesting discovery - the same error happens when I try to create a random symlink:
provisioner:
name: ansible
inventory:
links:
whatever: ../../../../env/live/inventory/whatever
But the link gets created:
$ ll $MOLECULE_EPHEMERAL_DIRECTORY | grep whatever
lrwxr-xr-x 1 tomasz staff 115B Mar 18 11:38 whatever -> /Users/tomasz/ansible-playbooks/haproxy/molecule/default/../../../../env/live/inventory/whatever
Just by reading this, what is strange is that the links should be created under $MOLECULE_EPHEMERAL_DIRECTORY/inventory not directly under $MOLECULE_EPHEMERAL_DIRECTORY.
I'll try to look more into it.
Do I understand correctly that the fix is merged into 2.20? When will you release that version and make it available via pip?
There's no fix yet AFAIK @TomaszKlosinski and the release date for v2.20 is still not clear.
I didn't react but using hosts in links is not supported in molecule 2.19.0.
It was added in 2.20 which isn't released yet.
One thing that could be done is checking the keys passed to links.
There is no check today. So as you noticed, you can pass whatever. This should raise an error.
Thanks for the information. I'll test this tomorrow with 2.20 or devel.
I've upgraded to 2.20 and it seems to work fine. Thanks for the help.
That's great :+1:
Leaving open to track for https://github.com/ansible/molecule/issues/1845#issuecomment-474604047.
Most helpful comment
Just by reading this, what is strange is that the links should be created under
$MOLECULE_EPHEMERAL_DIRECTORY/inventorynot directly under$MOLECULE_EPHEMERAL_DIRECTORY.I'll try to look more into it.