Ansible错误:lxc模块不可导入。检查需求

Ansible错误:lxc模块不可导入。检查需求,ansible,devops,Ansible,Devops,我的任务看起来像这样 - name: Create a started container lxc_container: name: test-container-started container_log: true template: ubuntu state: started template_options: --release trusty 我得到以下错误: > TASK: [lxc | Create a st

我的任务看起来像这样

- name: Create a started container
    lxc_container:
      name: test-container-started
      container_log: true
      template: ubuntu
      state: started
      template_options: --release trusty
我得到以下错误:

> TASK: [lxc | Create a started container]
> **************************************  failed: [localhost] => {"failed": true, "parsed": false}
> BECOME-SUCCESS-azsyqtknxvlowmknianyqnmdhuggnanw failed=True msg='The
> lxc module is not importable. Check the requirements.' The lxc module
> is not importable. Check the requirements.
> 
> 
> FATAL: all hosts have already failed -- aborting

lxc_容器相对较新。 要运行lxc_容器模块,您需要确保目标主机上安装了pip包以及lxc

e、 g


我刚刚遇到了同样的问题,我通过确保在目标机器上
pip在系统范围内安装lxc-python2
解决了这个问题


在我的例子中,目标是通过
ansible\u connection=local
主机的localhost,我认为我可以通过
pip:name=lxc-python2
摆脱,但它安装在我当前的virtualenv中。

正确的答案是添加:
been:yes
就在
lxc\u容器
-module部分之前,以便获得root权限在目标主机上运行lxc命令

要使用lxc_容器模块,无需在目标主机上安装任何python2 lxc-support LIB,这要求此类支持仅在管理主机中可用。只有python2必须在目标主机中可用,才能用于当前的Ansible版本

有关:(在执行模块的主机上)的要求的更多信息,请参阅ansible文档

  • lxc>=1.0#操作系统软件包
  • python>=2.6#操作系统包
  • lxc-python2>=0.1#PIP包来自

如果您使用Debian或Ubuntu作为主机系统,则已有可用的
python lxc
软件包。安装它的最佳方法当然是Ansible,就在
lxc\u容器
任务之前:

  tasks:

    - name: Install provisioning dependencies
      apt: name=python-lxc

    - name: Create docker1.lxc container
      lxc_container:
        name: docker1
        ...
无需在目标主机上安装(系统范围)LIB即可使其正常工作。请参阅此处的更多信息:
  tasks:

    - name: Install provisioning dependencies
      apt: name=python-lxc

    - name: Create docker1.lxc container
      lxc_container:
        name: docker1
        ...