如何在Ansible中使用lxc_container模块?

时间:2016-03-24 16:24:45

标签: python ansible ansible-playbook lxc devops

我正在尝试运行这个剧本

---
- hosts: control
  become: yes
  tasks:
    - name: Stop All Linux Containers
      lxc_container: name={{ item }} state=started
      with_items:
        - app01
        - app02
        - lb01
        - db01

目标主机是localhost但它失败并显示以下错误

failed: [127.0.0.1] => (item=app01) => {"failed": true, "item": "app01",    "parsed": false}
BECOME-SUCCESS-rppgggxcewgndkgtnpptrgeglbfykput
failed=True msg='The lxc module is not importable. Check the requirements.'
The lxc module is not importable. Check the requirements

在此之后我尝试了

pip install lxc-python2 

(从另一个stackoverflow帖子看到它)但它也显示错误

lxc.c:27:30: fatal error: lxc/lxccontainer.h: No such file or directory

 #include <lxc/lxccontainer.h>

                              ^

compilation terminated.

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_dhruv/lxc-python2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ZKdf9M-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_dhruv/lxc-python2
Storing debug log for failure in /home/dhruv/.pip/pip.log

2 个答案:

答案 0 :(得分:2)

如果您尚未安装lxc-dev软件包,则可能会发生这种情况。目前碰巧debian repo不包含它,你必须从像ubuntu这样的第三方下载

答案 1 :(得分:0)

对于lxc_container -Ansible模块的正常操作,不需要在目标主机中存在该dev软件包(lxc-dev)或pip。目标主机和管理主机(运行Ansible的那个)中的LXC容器模块文档中列出的那些包中只需要python2。