upgrade connection plugin
This commit is contained in:
parent
900928acf9
commit
ab6a6531c6
@ -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
|
||||
```
|
||||
|
||||
USAGE
|
||||
=====
|
||||
|
@ -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 """
|
||||
|
Loading…
Reference in New Issue
Block a user