Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

ansible_host set to another variable fails

Aperta
#620 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ansible, python

Direzione di ricerca

Reproduce the failure with the shown host_vars/my_host.yml configuration, Python 3.8.6, pytest 6.2.4, testinfra 6.4.0, and Ansible 4.1.0. Start at the Ansible connection backend and determine whether ansible_host is expected to resolve this variable reference; done means either supporting the interpolation with coverage or documenting the confirmed limitation.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Trying to use ansible connection backend, it seems to fail when
ansible_host variable is set to another variable, like so inventories/host_vars/my_host.yml

---
network_interfaces:
  - name: ens3
    address: 10.254.14.18
    netmask: 255.255.255.0
    gateway: 10.254.14.1

ansible_host: "{{ network_interfaces[0]['address'] }}"

when running testinfra this results in:

E           RuntimeError: CommandResult(command=b"sudo /bin/sh -c 'getent ahosts mail.example.com'", exit_status=255, stdout=None, stderr=b"ssh: Could not resolve hostname {{ network_interfaces[0]['address'] }}: Name or service not known\r\n")

A workaround is changing the host inventory file like so, but this is
not ideal:

---
network_interfaces:
  - name: ens3
    address: 10.254.14.18
    netmask: 255.255.255.0
    gateway: 10.254.14.1

ansible_host: 10.254.14.18 

Is this a limitation in testinfra, or am I doing something wrong?

versions using:

Python 3.8.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
plugins: testinfra-6.4.0
ansible == 4.1.0
Lingua principale
Python
Stelle
2.5k
Fork
360
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pytest-dev/pytest-testinfra

Tutte le issue di pytest-dev/pytest-testinfra

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.