我试图使用Ansible容器作为一个基本示例,该示例应该在映像中安装Node。当我使用ansible-container build命令时,在成功构建导体映像之后,它将失败第一个任务,并出现与sudo相关的错误。所讨论的任务需要执行root特权。
我正在运行Debian /Linux9.2(拉伸),通过Docker存储库安装了Docker17.09.0-ce。我尝试使用来自Debian拉伸(2.2.1.0-2)和Pypi (2.4.1.0)的Ansible。我尝试了Pypi (0.9.3rc0)和最新的Git源代码中的。我总是得到完全相同的错误输出。
Ansible模块抱怨如下:
sudo: error while loading shared libraries: libsudo_util.so.0: cannot open shared object file: No such file or directory正在运行的任务如下所示:
- name: Add the Node Source repository signing certificate to APT
apt_key:
id: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280
keyserver: hkps://hkps.pool.sks-keyservers.net
become: yes指挥家和我试图创建的服务都使用debian:stretch基图像。
我运行ansible-container build命令时,sudo已经准备好了,因为只有root可以访问我的系统上的Docker。
这是我的container.yml的内容
version: "2"
settings:
conductor:
base: debian:stretch
project_name: container_test
services:
nodejs:
from: debian:stretch
roles:
- nodejs
registries: {}以下是完整的错误输出:
Building Docker Engine context...
Starting Docker build of Ansible Container Conductor image (please be patient)...
Parsing conductor CLI args.
Docker™ daemon integration engine loaded. Build starting. project=container_test
Building service... project=container_test service=nodejs
PLAY [nodejs] ******************************************************************
TASK [Gathering Facts] *********************************************************
ok: [nodejs]
TASK [nodejs : Add the Node Source repository signing certificate to APT] ******
fatal: [nodejs]: FAILED! => {"changed": false, "module_stderr": "sudo: error while loading shared libraries: libsudo_util.so.0: cannot open shared object file: No such file or directory\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 127}
to retry, use: --limit @/tmp/tmpTRBQDe/playbook.retry
PLAY RECAP *********************************************************************
nodejs : ok=1 changed=0 unreachable=0 failed=1
ERROR Error applying role! engine=<container.docker.engine.Engine object at 0x7f84da0c5ed0> exit_code=2 playbook=[{'hosts': u'nodejs', 'roles': ['nodejs'], 'vars': {}}]
Traceback (most recent call last):
File "/usr/local/bin/conductor", line 11, in <module>
load_entry_point('ansible-container', 'console_scripts', 'conductor')()
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/cli.py", line 408, in conductor_commandline
**params)
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/core.py", line 843, in conductorcmd_build
raise RuntimeError('Build failed.')
RuntimeError: Build failed.
Conductor terminated. Cleaning up. command_rc=1 conductor_id=e8899239ad1017a89acc97396d38ab805d937a7b3d74e5a7d2741d7b1124bb0c save_container=False
ERROR Conductor exited with status 1发布于 2017-11-20 13:22:36
我找到了原因:
基本图像debian:stretch不包括sudo。因此,解决方案是将become_method设置为su。通常,这可以在每个任务、主机或剧本中完成。由于不清楚游戏手册的对应位置在中,以及主机的概念是如何应用的,所以我实际上只能选择使用任务级别。
我决定添加一个在映像中安装sudo的角色,并且只将该角色中的孤立任务的become_method设置为su。在应用角色时,不需要做进一步的更改,原始任务也可以工作。
接下来的一个问题是,也没有安装GnuPG来正确地完成apt_key模块任务。以下解决方案解决了这两个问题:
- become: yes
become_method: su
block:
- name: Update package cache
apt:
update_cache: yes
cache_valid_time: 86400
- name: Install GnuPG
package:
name: gnupg2
state: present
- name: Install sudo
package:
name: sudo
state: present据推测,一个更清晰的选项是生成一个已经包含了这些依赖项的基本映像,以允许更简化的AnbleContainer映像生成。
https://stackoverflow.com/questions/47280887
复制相似问题