Mic92 / ansible-lxc

Ansible Connection Plugin for lxc containers (https://linuxcontainers.org/)
GNU General Public License v3.0
17 stars 6 forks source link

Connection to container failing on file copy #1

Closed joaocc closed 9 years ago

joaocc commented 9 years ago

Hi, I am trying to get this to run on Ubuntu 14.04 with LXC 1.0.6 and Ansible v1.8.2. When I try to connect to a freshly installed guest (template ubuntu-cloud / trusty), I get the following error:

<lxc-demo> THIS IS A LOCAL LXC DIR
<lxc-demo> REMOTE_MODULE setup
<lxc-demo> EXEC ['/usr/bin/lxc-attach', '--name', 'lxc-demo', '--', '/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1420214512.67-65457909308433 && echo $HOME/.ansible/tmp/ansible-tmp-1420214512.67-65457909308433']
<lxc-demo> PUT /tmp/tmpGYMeY7 TO overlayfs:/var/lib/lxc/LXC-Template-1404/rootfs:/var/lib/lxc/lxc-demo/delta0/home/vagrant/.ansible/tmp/ansible-tmp-1420214512.67-65457909308433/setup

Traceback (most recent call last):
  File "/usr/share/ansible_plugins/connection_plugins/lxc/lxc.py", line 87, in _copy
    shutil.copyfile(in_path, out_path)
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:

IOError: [Errno 2] No such file or directory: u'overlayfs:/var/lib/lxc/LXC-Template-1404/rootfs:/var/lib/lxc/lxc-demo/delta0/home/vagrant/.ansible/tmp/ansible-tmp-1420214512.67-65457909308433/setup'
fatal: [lxc-demo] => failed to transfer file to overlayfs:/var/lib/lxc/LXC-Template-1404/rootfs:/var/lib/lxc/lxc-demo/delta0/home/vagrant/.ansible/tmp/ansible-tmp-1420214512.67-65457909308433/setup

After this, I confirm that the /var/lib/lxc/lxc-demo/delta0/home/vagrant/.ansible/tmp/ansible-tmp-1420214512.67-65457909308433 folder exists, but is empty.

Any ideas on what might be going wrong? Thanks

Mic92 commented 9 years ago

It seems like building the destination path does not work, when using overlayfs. What is the content of lxc.rootfs on your system?

joaocc commented 9 years ago

in the config file for the container, I have

lxc.rootfs = overlayfs:/var/lib/lxc/LXC-Template-1404/rootfs:/var/lib/lxc/lxc-demo/delta0
Mic92 commented 9 years ago

In my setup, I currently don't use overlayfs, but does it helps, if you replace the _root_fs() method in lxc.py

def _root_fs(self):
    rootfs = self.container.get_running_config_item("lxc.rootfs")
    if not rootfs:
        raise errors.AnsibleError("rootfs not set in configuration for %s") % self.host
    return rootfs

with:

def _root_fs(self):
    import re
    rootfs = self.container.get_running_config_item("lxc.rootfs")
    # overlayfs use the scheme:
    #   overlayfs:/var/lib/lxc/LXC-Template-1404/rootfs:/var/lib/lxc/lxc-demo/delta0
    match = re.match(r'^overlayfs:.+?rootfs:(.+)', rootfs)
    if match:
        rootfs = match.group(1)
    if not rootfs:
        raise errors.AnsibleError("rootfs not set in configuration for %s") % self.host
    return rootfs
joaocc commented 9 years ago

That did the trick! I sent a pull request in case you want to add this to your repo. Thanks a lot.