Unify usage of sudo() and ansible(..., become=true, become_user="...")
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- Python
- Stelle
- 2.5k
- Fork
- 360
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pytest-dev/pytest-testinfra
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 58/100
pytest-dev/pytest-testinfra#815 ·
-
service is_enabled does not work with exit code 4Forse già presa @pfuntner l’ha presa 574 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
pytest-dev/pytest-testinfra#801 · 1 commento ·
-
Chroot backendAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
pytest-dev/pytest-testinfra#789 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
pytest-dev/pytest-testinfra#788 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
pytest-dev/pytest-testinfra#786 ·
Tutte le issue di pytest-dev/pytest-testinfra
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/agent-lightning#661 ·
I maintainer di solito rispondono entro 2 giorni
-
area/profiles comp/cli P3 type/feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
NousResearch/hermes-agent#146372 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] OpenAI-compatible embedding model alias breaks embedder constructionForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistenciesForse già presa @github-actions l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
GeoSeries scale and skew tests fail with pytest 9.2.0Forse già presa @jiayuasu l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno