Unify usage of sudo() and ansible(..., become=true, become_user="...")
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by tracing the sudo() context manager and the direct ansible module invocation shown in the example, then compare how explicit become and become_user arguments are handled. Done means an ansible module called inside sudo(user="root") runs as root without explicit become arguments, while the existing explicit-become behavior remains unchanged; verify this with the supplied example.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
It's possible to elevate privileges with sudo() in a context manager. This works fine.
Unfortunately, the privilege elevation does not affect the direct invocation of Ansible modules. That means Ansible modules must get elevated privileges with become=True, become_user="root" additionally even if sudo permissions are already set.
Please extend Testinfra to automatically use the elevated privileges from the sudo context manager when calling Ansible modules.
Example:
def test_sudo(host):
with open("result.txt", "w") as f:
whoami_wo_sudo = ansiblehost.check_output("id")
shell_wo_sudo = ansiblehost.ansible("shell id", check=False)
with ansiblehost.sudo(user="root"):
whoami_w_sudo = ansiblehost.check_output("id")
shell_w_sudo = ansiblehost.ansible("shell id", check=False)
shell_w_become = ansiblehost.ansible("shell id", check=False, become=True, become_user="root")
print(f"""\
Test results
============
without sudo:
OS cmd "whoami": {whoami_wo_sudo}
Ansible module "shell": {shell_wo_sudo["stdout"]}
with sudo:
OS cmd "whoami": {whoami_w_sudo}
with sudo & without become:
Ansible module "shell": {shell_w_sudo["stdout"]}
with sudo & with become:
Ansible module "shell": {shell_w_become["stdout"]}
""", file=f)
# cat result.txt
Test results
============
without sudo:
OS cmd "whoami": uid=999(ansible) gid=999(ansible) groups=999(ansible)
Ansible module "shell": uid=999(ansible) gid=999(ansible) groups=999(ansible)
with sudo:
OS cmd "whoami": uid=0(root) gid=0(root) groups=0(root)
with sudo & without become:
Ansible module "shell": uid=999(ansible) gid=999(ansible) groups=999(ansible)
with sudo & with become:
Ansible module "shell": uid=0(root) gid=0(root) groups=0(root)
- Ngôn ngữ chính
- Python
- Star
- 2.5k
- Fork
- 359
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pytest-dev/pytest-testinfra
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 58/100
pytest-dev/pytest-testinfra#815 ·
-
service is_enabled does not work with exit code 4Có thể đã có người làm @pfuntner đã nhận 574 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
pytest-dev/pytest-testinfra#801 · 1 bình luận ·
-
Chroot backendĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
pytest-dev/pytest-testinfra#789 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
pytest-dev/pytest-testinfra#788 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
pytest-dev/pytest-testinfra#786 ·
Tất cả issue của pytest-dev/pytest-testinfra
Issue tương tự
-
factory
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Arize-ai/phoenix#17420 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
FireDynamics/LEDSmokeAnalysis#176 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
PC
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Make `ocifs` optionalĐang mởdependencies
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
dlt-contrib/dlt-filesystem#51 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày