Spec-Zone.ru › Ansible

containers.podman.podman_unshare become – Выполнение задач с использованием podman unshare

Примечание

Этот плагин become входит в коллекцию containers.podman (версия 1.16.1).

Возможно, эта коллекция уже установлена, если вы используете пакет 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.io/en/latest/markdown/podman-unshare.1.html

Параметры

Параметр

Комментарии

become_exe

строка

Исполняемый файл sudo

По умолчанию: "sudo"

Настройка:

  • Элементы INI:

    [privilege_escalation]
    become_exe = sudo
    
    [sudo_become_plugin]
    executable = sudo
    
  • Переменная окружения: ANSIBLE_BECOME_EXE
  • Переменная окружения: ANSIBLE_SUDO_EXE
  • Переменная: ansible_become_exe
  • Переменная: ansible_sudo_exe

become_pass

строка

Пароль для передачи sudo

Настройка:

  • Элемент INI:

    [sudo_become_plugin]
    password = VALUE
    
  • Переменная окружения: ANSIBLE_BECOME_PASS
  • Переменная окружения: ANSIBLE_SUDO_PASS
  • Переменная: ansible_become_password
  • Переменная: ansible_become_pass
  • Переменная: ansible_sudo_pass

become_user

строка

Пользователь, от имени которого нужно выполнить задачу («root» здесь не допустимо).

Настройка:

  • Элементы INI:

    [privilege_escalation]
    become_user = VALUE
    
    [sudo_become_plugin]
    user = VALUE
    
  • Переменная окружения: ANSIBLE_BECOME_USER
  • Переменная окружения: ANSIBLE_SUDO_USER
  • Переменная: ansible_become_user
  • Переменная: ansible_sudo_user

Примеры

- 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)

Подсказка

Элементы конфигурации для каждого типа имеют порядок приоритетов от низкого к высокому. Например, переменная, которая находится ниже в списке, переопределит переменную, расположенную выше.

Ссылки на коллекцию

  • Система отслеживания проблем
  • Репозиторий (исходный код)

© 2012–2018 Michael DeHaan
© 2018–2024 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/containers/podman/podman_unshare_become.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API