containers.podman.podman_unshare become – 使用 podman unshare 运行任务
注意
此 become 插件是 containers.podman 集合 (版本 1.16.2) 的一部分。
如果您使用的是 ansible
包,则可能已安装此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install containers.podman
。
要在剧本中使用它,请指定: containers.podman.podman_unshare
。
containers.podman 1.9.0 中的新增功能
摘要
此 become 插件允许您的远程/登录用户在其容器用户命名空间中执行命令。官方文档:https://docs.podman.org.cn/en/latest/markdown/podman-unshare.1.html
参数
参数 |
注释 |
---|---|
Sudo 可执行文件 默认值: 配置
|
|
传递给 sudo 的密码 配置
|
|
您“成为”以执行任务的用户(“root”此处不是有效值)。 配置
|
示例
- name: checking uid of file 'foo'
ansible.builtin.stat:
path: "{{ test_dir }}/foo"
register: foo
- ansible.builtin.debug:
var: foo.stat.uid
# The output shows that it's owned by the login user
# ok: [test_host] => {
# "foo.stat.uid": "1003"
# }
- name: mounting the file to an unprivileged container and modifying its owner
containers.podman.podman_container:
name: chmod_foo
image: alpine
rm: true
volume:
- "{{ test_dir }}:/opt/test:z"
command: chown 1000 /opt/test/foo
# Now the file 'foo' is owned by the container uid 1000,
# which is mapped to something completaly different on the host.
# It creates a situation when the file is unaccessible to the host user (uid 1003)
# Running stat again, debug output will be like this:
# ok: [test_host] => {
# "foo.stat.uid": "328679"
# }
- name: running stat in modified user namespace
become_method: containers.podman.podman_unshare
become: true
ansible.builtin.stat:
path: "{{ test_dir }}/foo"
register: foo
# By gathering file stats with podman_ushare
# we can see the uid set in the container:
# ok: [test_host] => {
# "foo.stat.uid": "1000"
# }
- name: resetting file ownership with podman unshare
become_method: containers.podman.podman_unshare
become: true
ansible.builtin.file:
state: file
path: "{{ test_dir }}/foo"
owner: 0 # in a modified user namespace host uid is mapped to 0
# If we run stat and debug with 'become: false',
# we can see that the file is ours again:
# ok: [test_host] => {
# "foo.stat.uid": "1003"
# }
作者
Janos Gerzson (@grzs)
提示
每种条目类型的配置条目具有从低到高的优先级顺序。例如,列表中较低的变量将覆盖列表中较高的变量。