Ansible 容器无法加载 libsudo_util.so.0 以执行特权模块
Ansible Container unable to load libsudo_util.so.0 for privileged module execution
我正在尝试使用 Ansible Container 作为一个基本示例,该示例应该在映像中安装 Node。当我使用 ansible-container build
命令时,在成功构建导体图像后,第一个任务失败并出现 sudo
相关错误。相关任务需要 root
权限才能执行。
我正在 运行ning Debian GNU/Linux 9.2(stretch),通过 Docker APT 存储库安装了 Docker 17.09.0-ce。我尝试使用来自 Debian Stretch (2.2.1.0-2) 和 Pypi (2.4.1.0) 的 Ansible。我从 Pypi (0.9.3rc0) 和最新的 Git 来源尝试了 Ansible Container。我总是得到完全相同的错误输出。
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
我找到了原因:
基本图像 debian:stretch
不包含 sudo
。因此,解决方案是将 become_method
设置为 su
。通常,这可以按任务、主机或剧本完成。因为在 Ansible 容器中相当于剧本的位置以及主机概念的应用方式并不明显,所以我只能选择使用任务级别。
我决定添加一个在映像中安装 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
据推测,一个更干净的选择是生成一个已经包含这些依赖项的基础镜像,以允许更简化的 Ansible 容器镜像生成。
我正在尝试使用 Ansible Container 作为一个基本示例,该示例应该在映像中安装 Node。当我使用 ansible-container build
命令时,在成功构建导体图像后,第一个任务失败并出现 sudo
相关错误。相关任务需要 root
权限才能执行。
我正在 运行ning Debian GNU/Linux 9.2(stretch),通过 Docker APT 存储库安装了 Docker 17.09.0-ce。我尝试使用来自 Debian Stretch (2.2.1.0-2) 和 Pypi (2.4.1.0) 的 Ansible。我从 Pypi (0.9.3rc0) 和最新的 Git 来源尝试了 Ansible Container。我总是得到完全相同的错误输出。
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
我找到了原因:
基本图像 debian:stretch
不包含 sudo
。因此,解决方案是将 become_method
设置为 su
。通常,这可以按任务、主机或剧本完成。因为在 Ansible 容器中相当于剧本的位置以及主机概念的应用方式并不明显,所以我只能选择使用任务级别。
我决定添加一个在映像中安装 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
据推测,一个更干净的选择是生成一个已经包含这些依赖项的基础镜像,以允许更简化的 Ansible 容器镜像生成。