Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

ansible_host set to another variable fails

Abierto
#620 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
ansible, python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Python
Estrellas
2.5k
Forks
360
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pytest-dev/pytest-testinfra

Todos los issues de pytest-dev/pytest-testinfra

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.