upgrade connection plugin

This commit is contained in:
Jörg Thalheim 2015-01-14 20:16:30 +00:00
parent 900928acf9
commit ab6a6531c6
2 changed files with 18 additions and 5 deletions

View File

@ -7,7 +7,11 @@ The plugin will use lxc-attach under the hood to connect to containers
INSTALL 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/ $ 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 $ 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 USAGE
===== =====

View File

@ -4,6 +4,8 @@ import distutils.spawn
import os,sys import os,sys
import subprocess import subprocess
import shutil import shutil
import traceback
import re
from ansible import errors from ansible import errors
from ansible.callbacks import vvv from ansible.callbacks import vvv
@ -20,6 +22,11 @@ class Connection(object):
def _root_fs(self): def _root_fs(self):
rootfs = self.container.get_running_config_item("lxc.rootfs") 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: if not rootfs:
raise errors.AnsibleError("rootfs not set in configuration for %s") % self.host raise errors.AnsibleError("rootfs not set in configuration for %s") % self.host
return rootfs return rootfs
@ -48,9 +55,9 @@ class Connection(object):
def _generate_cmd(self, executable, cmd): def _generate_cmd(self, executable, cmd):
if executable: if executable:
return [self.lxc_attach, "-e", "--name", self.host, "--", executable, "-c", cmd] return [self.lxc_attach, "--name", self.host, "--", executable, "-c", cmd]
else: 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): 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 """ """ run a command on the chroot """