Browse Source

upgrade connection plugin

master
Jörg Thalheim 7 years ago
parent
commit
ab6a6531c6
  1. 12
      connection_plugins/lxc/README.md
  2. 11
      connection_plugins/lxc/lxc.py

12
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
=====

11
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 """

Loading…
Cancel
Save