From ab6a6531c6c8552275bd62f8f2205d3eb118a397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 14 Jan 2015 20:16:30 +0000 Subject: [PATCH] upgrade connection plugin --- connection_plugins/lxc/README.md | 12 +++++++++--- connection_plugins/lxc/lxc.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/connection_plugins/lxc/README.md b/connection_plugins/lxc/README.md index 06098b9..dcf9405 100644 --- a/connection_plugins/lxc/README.md +++ b/connection_plugins/lxc/README.md @@ -7,7 +7,11 @@ The plugin will use lxc-attach under the hood to connect to containers INSTALL ======= -1. Clone the plugin in your ansible directory +* Install python2 version of lxc bindings: + + - https://github.com/lxc/python2-lxc + +* Clone the plugin in your ansible directory ``` $ mkdir -p /etc/ansible/connection_plugins/ @@ -21,9 +25,11 @@ $ mkdir -p /etc/ansible/connection_plugins/ $ git submodule add git@github.com:Mic92/ansible-lxc.git /etc/ansible/connection_plugins/lxc ``` -2. Then add lxc directory to plugin search path in `ansible.cfg`: +* Then add lxc directory to plugin search path in `ansible.cfg`: - connection_plugins = /usr/share/ansible_plugins/connection_plugins:/etc/ansible/connection_plugins/lxc +``` +connection_plugins = /usr/share/ansible_plugins/connection_plugins:/etc/ansible/connection_plugins/lxc +``` USAGE ===== diff --git a/connection_plugins/lxc/lxc.py b/connection_plugins/lxc/lxc.py index 7c3fb1a..128f4b1 100644 --- a/connection_plugins/lxc/lxc.py +++ b/connection_plugins/lxc/lxc.py @@ -4,6 +4,8 @@ import distutils.spawn import os,sys import subprocess import shutil +import traceback +import re from ansible import errors from ansible.callbacks import vvv @@ -20,6 +22,11 @@ class Connection(object): def _root_fs(self): 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 @@ -48,9 +55,9 @@ class Connection(object): def _generate_cmd(self, executable, cmd): if executable: - return [self.lxc_attach, "-e", "--name", self.host, "--", executable, "-c", cmd] + return [self.lxc_attach, "--name", self.host, "--", executable, "-c", cmd] else: - return "%s -e --name %s -- %s" % (self.lxc_attach, self.host, cmd) + return "%s --name %s -- %s" % (self.lxc_attach, self.host, cmd) def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable="/bin/sh", in_data=None, su=None, su_user=None): """ run a command on the chroot """